Create folders or file name equal to current date/time in Linux

There are various situations on a server or hosting, where we want to create a file or folder and have in its name the date it was created.

An example of a command in linux, by which we can create a folder, looks like this

mkdir FOLDERNAME_`date +%d-%m-%Y_%H-%M-%S`

Here is another example where we create a file with ping result (one file/hour) – command add all lines to the end of the file.

ping -i 3 -c 10 google.com >> ping-google.com_`date +%Y.%m.%d.%H`.txt &

where:

  • -i 3 => interval between successive packet transmissions.
  • -c 1200 =>  the number of times to send the ping request
  • -w 3600 =>  a timeout, in seconds, before ping exits, regardless of how many packets have been sent or received.
  • & => nohup command &   (detach a process from its terminal)
  • >>  => write the result in the file
byrev Written by:

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *