Flight Engineer
Flight Engineer
  • 615 Views

how to create one month logs with touch command in linux

Jump to solution

Hi all,

 

how to create multiple date log/file like one month create with touch command in Linux OS . if any one knows then could you please share the command .

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Flight Engineer
Flight Engineer
  • 563 Views

Re: how to create one month logs with touch command in linux

Jump to solution

How many files are you creating, and for what purpose? Do you want a file dated from one month ago? Use:

    touch -d "$(date -d '1 month ago')" one-month-ago

for that. If you want 30 days worth of timestamped files, use something like:

    for((day=0;day <= 30; day++)) do touch -d "$(date -d "$day days ago")" day-"$day" ;done

View solution in original post

0 Kudos
Reply
Loading...
2 Replies
Highlighted
Flight Engineer
Flight Engineer
  • 564 Views

Re: how to create one month logs with touch command in linux

Jump to solution

How many files are you creating, and for what purpose? Do you want a file dated from one month ago? Use:

    touch -d "$(date -d '1 month ago')" one-month-ago

for that. If you want 30 days worth of timestamped files, use something like:

    for((day=0;day <= 30; day++)) do touch -d "$(date -d "$day days ago")" day-"$day" ;done

View solution in original post

0 Kudos
Reply
Loading...
Highlighted
Mission Specialist
Mission Specialist
  • 509 Views

Re: how to create one month logs with touch command in linux

Jump to solution

Why would you even want to do this?  It sounds like you're over thinking a few things.

Log rotate will automatically create them if setup with the correct parameters, compress and if possible restart the service if necessary.

 

A quick google search provided me with the link to RHEL6.  If you want RHEL7, or others, a search will provide you with explicit steps:

 

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/s2-lo...

Reply
Loading...
Join the discussion
You must log in to join this conversation.