Ankush Panday
Ankush Panday

Reputation: 83

Rename Multiple Files in a Directory in Linux

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

Answers (2)

Dinesh
Dinesh

Reputation: 4567

rename @timestamp@ $(date +%Y%m%d%H%M%S) *@timestamp@*

See also man rename for details and more examples

Upvotes: 1

JohnDoe90
JohnDoe90

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

Related Questions