user1710563
user1710563

Reputation: 387

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?

Upvotes: 12

Views: 22077

Answers (2)

James Waldby - jwpat7
James Waldby - jwpat7

Reputation: 8711

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.

Upvotes: 20

choroba
choroba

Reputation: 242443

Does the following do what you need?

date "+%b_%d_%Y_%H.%M.%S" 

Upvotes: 4

Related Questions