Reputation: 83
I have a requirement to rename all files (not single file) in a directory with the current time stamp in LINUX.
For example:
abcd_001_@timestamp@_12345.txt, abcd_002_@timestamp@_56789.txt
to
abcd_001_20141205063435_12345.txt, abcd_002_20141205063435_56789.txt
I have used rename
command but unable to change the names. Could someone help me here.
A quick reply will be appreciated.
Upvotes: 0
Views: 132
Reputation: 4567
rename @timestamp@ $(date +%Y%m%d%H%M%S) *@timestamp@*
See also man rename
for details and more examples
Upvotes: 1
Reputation: 368
Do you just want to rename them manually, then you could use something like this:
rename 's/@timestamp@/20141205063435/' *.txt
If you want to do it automatically you could use the date
command to give you the current date.
rename "s/$(date)/$(date +%Y%m...)/" *.txt
Upvotes: 0