Need help with shell script - renaming multiple files
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
For good measure, I thought I'd throw this one in too. It's a perl script, but it still requires the find command format earlier.
if ($#ARGV > -1 )
$filename = shift;
$new_filename = $filename;
if ( $new_filename =~ /\.dd-/ )
$new_filename =~ s/\.dd-//g;
if ( $new_filename =~ /-dead-[0-9]*>/ )
$new_filename =~ s/-dead-[0-9]*>//g;
if( $filename ne $new_filename )
system mv, $filename, $new_filename;
It will rename the file in one action. It'll take care of the ".dd-" and "-dead-" portions. Create the script (I named it file_rename.pl), make it executable, and then (assuming it's in the same dir as the files to rename) type this at your bash prompt (you're creating a mini-wrapper script):
ls | while read filename; do ./file_rename.pl $filename; done
I have a problem: plenty of Japanese files, with disguised names, such as: V^[N[X܂̓X@�5 .doc (invalid Unicode)
In some instances they have no extention, or the period before:
The lenght of the names is always different.
All these files were imported from Windzoo 97.
OpenOffice opens them beautifully (btw, the latest OpenOffice works like charm, and loads really fast! I also solved the problem of printing margins.), if the names look like something more civilized, say, 1.doc, 2.doc etc.
I need a script wich will batch rename all these files, replacing the names with a number and *.doc extention.
I read mv and rename man, but this task is beyond my skills.
Can anyone post here a ready to use script, or something I could start with? Thanks in advance.
P.S. rename ".doc (invalid Unicode)" ".doc" *
works, but I don't know what to do with the mess before the extension
This looks nice. It should work and I will give it a try now.
BTW, Today while I was messing up with these scripts, I renamed all folders in the /root directory (incidentally I run the script as root -- luckily I have not donemore damage!)
Anyway, all folders in /root were renamed in 1.doc 2.doc 3.doc
I figured out that one of them was tmp folder, another was Desktop, the third folder contains log files, auto-install.pl script etc. I don't remember what was the name of this folder. Do you have any idea?
As for the problem with renaming the directories in root, well, it all depends on your installation. There are some standard ones:
The one that contains log files is typically /var.