Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append the time stamp to a file name in Ubuntu

I have a bash script that I use to backup the contents of a SSD every day however I use the following command in the script to name the file

zip -r ssd-$(date "+%b_%d_%Y").zip ../ssd

It already appends the month, day, and year to the file name however how can I modify that to also append the timestamp of the server onto the file name as well?

like image 855
user1710563 Avatar asked Oct 07 '12 23:10

user1710563


2 Answers

Add _%H_%M_%S into the date-format string as well. For example, date +%b_%d_%Y_%H_%M_%S produces a string like Oct_07_2012_17_57_36. For a shorter string, consider format %s; eg, date +%s produces a string like 1349654346, the number of seconds since 1970-01-01 00:00:00 UTC.

like image 62
James Waldby - jwpat7 Avatar answered Oct 21 '22 18:10

James Waldby - jwpat7


Does the following do what you need?

date "+%b_%d_%Y_%H.%M.%S" 
like image 22
choroba Avatar answered Oct 21 '22 16:10

choroba