Results 1 to 3 of 3
I am trying to rename multiple files in a directory and add the Date/Time stamp to the file name.
Example:
file1.txt
file2.txt
file3.txt
Renamed to
2009_02_01_21.txt
2009_02_02_21.txt
2009_02_03_21.txt
I am ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-01-2009 #1Just Joined!
- Join Date
- Feb 2009
- Posts
- 4
Need Help renaming multiple files
I am trying to rename multiple files in a directory and add the Date/Time stamp to the file name.
Example:
file1.txt
file2.txt
file3.txt
Renamed to
2009_02_01_21.txt
2009_02_02_21.txt
2009_02_03_21.txt
I am able to accomplish this using this command:
mv file1.txt "`date +%Y_%m%d_%H`".txt
But I want to automate this task, I have many files to process and I dont want to do them one by one.
I already tried this but it does not work
mv *.txt "`date +%Y_%m%d_%H`".txt
Thanks in advance for any help.
- 02-01-2009 #2Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
I'm assuming you want to take the number from the original filename and put it in the third number position. This is quick and hackish, but it might get you started:
Code:for i in *;do mv "$i" "$(date +%Y_%m_$(echo $i |sed s/file// |sed s/.txt//)_%d)".txt;done
- 02-01-2009 #3Just Joined!
- Join Date
- Feb 2009
- Posts
- 4


Reply With Quote

