How to rename all files in a directory adding unix current date prefix

I am using the following command to rename all files without spaces by adding "Hello" prefix

for FILENAME in *; do mv $FILENAME Hello_$FILENAME; done 

      

I am using the following command to get unix datestamp

date +%s

      

How to replace Hello

with a conclusion date +%s

?

+3


source to share


1 answer


If I understand your question, you can use $(date +%s)

command substitution syntax to get the output of a command (and I suggest quotes) like



for i in *; do mv "$i" "$(date +%s)_$i"; done

      

+7


source







All Articles