I’m trying to tar a large directory, and I’d like the output file to contain the date. Here’s what I have so far.
tar -zcvf "mywebsite website backup" $(date "+%Y-%m-%d %T") public_html
This doesn’t quite work though. As an example, I’m trying to get the single string below to be the file name. The call to date is working fine and I don’t need help with that, but I’m not sure how to concatenate the “my website backup” with the output from date without first storing them in variables (which seems ham fisted).
mywebsite website backup 2001-12-01 12:04:03
Variables and such are interpreted within double quotes (but not within single quotes):
(I added the
.tgzsuffix, you apparently forgot.)If you had no white space in your file name, you could do it without quotes:
Or you could turn it around and use the fact that
datealready accepts a format string:(Still needs double quotes around
$()if the file name contains white space.)NB: For various reasons it is usually not a good idea to include colons in file names.