Home > Linux, Tips and Tricks > Linux Add date to file names

Linux Add date to file names

Sometimes when you are running cron jobs and creating log files, you need a way to add date and time-stamps to the files names. Here is something you can try – I am adding timestamps to the file names below

mkdir test
cd test
echo "file-1" > log-file-$(date +%s).log  
echo "file-2" > $(date +%s)-log-file.log
ls -la

%s gives the timestamp

To see all the date formats refer to this excellent article: http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/

Advertisements
Categories: Linux, Tips and Tricks
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: