Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OS X terminal command to create a file named on current date

I have set up a cron task and I want to save the output to a file. The file should have the name based on the time at which the cron was executed (eg.: 20110317-113051.txt).

My actual cron command is as follows:

lynx -dump http://somesite/script.php > /Volumes/dev0/textfile.txt

I want the textfile to be replaced by some sort of unique time stamp.

I've tried

lynx -dump http://somesite/script.php > $(date).txt
but I receive an error that the command is ambiguous.

Thanks for your help!

Sorin

like image 336
Sorin Buturugeanu Avatar asked Mar 17 '11 09:03

Sorin Buturugeanu


1 Answers

You need to quote the file name, since date by default will have special characters in it:

lynx -dump http://somesite/script.php > "$(date).txt"

As @Gareth says though, you should specify a format string for date, so that you get a more readable/manageable file name, e.g.

lynx -dump http://somesite/script.php > "$(date +%Y%m%d-%H%M%S).txt"
like image 57
Paul R Avatar answered Sep 17 '22 13:09

Paul R