I'm trying to append the current date to the end of a file name like this.

TheFile.log.2012-02-11

This is what i have

set today = 'date +%Y'
mkdir -p The_Logs &
find . -name The_Logs -atime -1 -type d -exec mv \{} "The_Logs_+$today" \; &

All i see is the name of the file and nothing else How do I append a current date to a filename?

Best Answer


More than likely it is your use of set . That will assign 'today', '=' and the output of the date program to positional parameters (aka command-line arguments). You want to use a shell c that you mark as bash

today=`date +%Y-%m-%d.%H:%M:%S` # or whatever pattern you desire

Notice the lack of spaces around the equal sign.

You also do not want to use & at the end of your statements; which causes the shell to not wait for the command to finish. Especially when one relies on the next. The find command could fail because it is started before the mkdir .