I tried to append the current day and time to the existing file name in shell scripting and I found my command is not working as expected.
For example, if my file name is f1.log and I nees to append it along with current time. This appended version must be used for further processing of the file.
I tried with the following script but getting an error
now=$(date +"%m-%d-%Y/%T")
echo hi >>time.log
mv "time.log" "time.$now.log" (error here : file or directory not found)
echo hello >> time.log$now (have to continue processing with new file)
The problem is with shell’s interpertation of
/in yourdate +"%m-%d-%Y/%T".Change it to a
-instead (or something else, as long as it’s not/or another meta character that will make the files difficult to work with in the future)