Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bulk rename files in Redhat 2

Status
Not open for further replies.

zhenning

Technical User
Sep 22, 2005
50
CA
I use Redhat AS 3 and I want to remove '2005' in a bulk of file names. I tried following command:

rename -v 's/92005/9/' *2005*

Then I got no output and the files names are not changed. What could be wrong here?

Thanks,
Zhenning
 
Code:
rename -v 's/2005//' *

I would first try it out with the -n option.

Code:
rename -vn 's/2005//' *

Cheers

QatQat




Life is what happens when you are making other plans.
 
Hi QatQat,

I tried your command and I got the same thing, no output and file names are not changed.. Weird..

Thanks,
Zhenning
 
can you post a sample of your file names?

QatQat

Life is what happens when you are making other plans.
 
-rw-r--r-- 1 root root 0 Sep 19 2005 17142509192005.txt
-rw-r--r-- 1 root root 0 Sep 19 2005 17410709192005.txt
-rw-r--r-- 1 root root 0 Sep 19 2005 17413209192005.txt

[root@kojak dxu]# rename -vn 's/2005//' *
[root@kojak dxu]# ll *2005*
-rw-r--r-- 1 root root 0 Sep 19 2005 17142509192005.txt
-rw-r--r-- 1 root root 0 Sep 19 2005 17410709192005.txt
-rw-r--r-- 1 root root 0 Sep 19 2005 17413209192005.txt
 
This may sound silly... but would something like:

Code:
mv ??????????2005.txt ??????????.txt
work?

Just my 2¢
"Life gets mighty precious when there's less of it to waste." -Bonnie Raitt "Nick of Time"
--Greg
 
It seems like when moving multiple files, the DEST must be a directory:

[root@kojak dxu]# mv ??????????2005.txt ??????????.txt
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.
 
Here's a different tact. Run it through a loop and modify each filename individually:
Code:
[todd@tlyons ~/test]$ touch 17142509192005.txt 17410709192005.txt 17413209192005.txt
[todd@tlyons ~/test]$ ls
17142509192005.txt  17410709192005.txt  17413209192005.txt
[todd@tlyons ~/test]$ for F in *.txt; do newF=`echo $F | sed s/2005//`; mv $F $newF; done
[todd@tlyons ~/test]$ ls
1714250919.txt  1741070919.txt  1741320919.txt
[todd@tlyons ~/test]$
Adjust the for F in *.txt portion if you want to change which files it processes. If for some reason you have a VERY large list of files (exceeds a hard limit on commandline length), then you may have to do files in groups.
 

Using the 'rename' command works if you use it this way:

$ ls
17142509192005.txt 17410709192005.txt 17413209192005.txt

$ rename 2005.txt .txt *

$ ls
1714250919.txt 1741070919.txt 1741320919.txt

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top