cancel
Showing results for 
Search instead for 
Did you mean: 
jeesshnasree
Starfighter Starfighter
Starfighter
  • 2,952 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
Jeff_Schaller
Flight Engineer
Flight Engineer
  • 2,900 Views

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
2 Replies
Jeff_Schaller
Flight Engineer
Flight Engineer
  • 2,901 Views

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

0 Kudos
Tiny_MN
Mission Specialist
Mission Specialist
  • 2,846 Views

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...

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