Results 1 to 4 of 4
Hi all,
I want to rename a bunch of files. I am a beginning linux user. I have this problem where at my work we keep archived versions of all ...
- 09-19-2008 #1Just Joined!
- Join Date
- Sep 2008
- Location
- Washington DC
- Posts
- 5
Renaming multiple files quickly
Hi all,
I want to rename a bunch of files. I am a beginning linux user. I have this problem where at my work we keep archived versions of all sorts of files. The person before be named them as with the date, time, and then the filename. For example, 25July2008_18:36_op_table.PDF. This works fine, except my bosses are not familiar with linux, and although a lot of work is done in linux, they like to look at things from Windows. This filename is jibberish when it appears in the Windows side of things (via mapping a directory) because there is a colon in it. I want to rename it as follows:
mv 25July2008_18:36_op_table.PDF 25July2008_18_36_op_table.PDF
However there are probably 10,000 files I need to do this too, these files have different date stamps, timestamps, extensions, filenames, and are in different directories. To be specific they are in about 12-15 directories.
My current way is to use the mved command in each directory. However I can't get it to work. The command is found but I am having trouble giving it the right syntax. Help?
Thanks in advance.
Ben
- 09-19-2008 #2Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,695
The rename command supports regular expressions and can do this quickly.
Examples
Code:rename ":" "_" *.PDF
- 09-19-2008 #3Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
If you like what you see, remove "echo" from the command to do the real work.Code:find /path/to/dir -type f | while read file; do echo mv "$file" "${file/:/_}"; done
- 09-19-2008 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
if you can use Python, you can try this script
eg usage:
# touch 25July2008_18:36_op_table.PDF
# touch 26July2008_19:36_op_table.PDF
# ls -1
25July2008_18:36_op_table.PDF
26July2008_19:36_op_table.PDF
# filerenamer.py -p ":" -e "_" -l "*PDF"
To be renamed or deleted): [ /home/25July2008_18:36_op_table.PDF ] to [ /home/25July2008_18_36_op_table.PDF ]
To be renamed or deleted): [ /home/26July2008_19:36_op_table.PDF ] to [ /home/26July2008_19_36_op_table.PDF ]
# filerenamer.py -p ":" -e "_" "*PDF" # remove -l to commit
/home/25July2008_18:36_op_table.PDF is renamed to /home/25July2008_18_36_op_table.PDF
/home/26July2008_19:36_op_table.PDF is renamed to /home/26July2008_19_36_op_table.PDF
# ls -1
25July2008_18_36_op_table.PDF
26July2008_19_36_op_table.PDF


Reply With Quote