Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I use the following command to rename all files with no spaces adding prefix "Hello"

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

I use the following command to get unix datestamp

date +%s

How do I replace Hello with date +%s output?

like image 441
Andy Avatar asked Dec 10 '25 07:12

Andy


1 Answers

If I understand your question, then you could use the $(date +%s) command substitution syntax to get the command output (and I suggest quotes) like

for i in *; do mv "$i" "$(date +%s)_$i"; done
like image 130
Elliott Frisch Avatar answered Dec 11 '25 21:12

Elliott Frisch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!