Andy
Andy

Reputation: 613

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?

Upvotes: 3

Views: 2294

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201447

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

Upvotes: 8

Related Questions