Linux, Tips and TricksLinux 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/

Categories: Linux, Tips and Tricks

Comments

No Comments Yet. Be the first?

Post a comment

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