| | |
bulk rename files
![]() |
•
•
Join Date: Oct 2006
Posts: 42
Reputation:
Solved Threads: 0
Hi,
I just need to know a simple command to bulk renaming.
I have hundreds of .DEB files. I want to remove 4%3a from all file names.
example :
old name :
ark-kde4_4%3a4.0.3-0ubuntu4_i386.deb
new name :
ark-kde4_4.0.3-0ubuntu4_i386.deb
I know there is a "rename" command but I don't know it's use.
Thank you
I just need to know a simple command to bulk renaming.
I have hundreds of .DEB files. I want to remove 4%3a from all file names.
example :
old name :
ark-kde4_4%3a4.0.3-0ubuntu4_i386.deb
new name :
ark-kde4_4.0.3-0ubuntu4_i386.deb
I know there is a "rename" command but I don't know it's use.
Thank you
Usually we use the "mv" (move) command to rename a file. Try something like this!
If the files are all in one directory, you can run this from in that directory and it should get all of them. It's very basic, so if you run into any problems let us know. It worked on a test run with files formatted like your example.
Hope this helps!
-G
#!/bin/sh for FILE in $(find . -type f -name '*4%3a*'); do NEWNAME=$(echo $FILE|sed s/'4%3a'//) mv -v $FILE $NEWNAME done
If the files are all in one directory, you can run this from in that directory and it should get all of them. It's very basic, so if you run into any problems let us know. It worked on a test run with files formatted like your example.
Hope this helps!
-G
Forgot to add comments!
#!/bin/sh # first we need a list to work from. the # "for" statement will loop through the results # of our "find" command, using each result in turn # as "$FILE". The find command that I used will # recursive look in subdirectories as well. You can # fix that with a flag, or you could use something # like `ls |grep '4%3a'` for FILE in $(find . -type f -name '*4%3a*'); do # here we use sed to get rid of the unwanted string # and store it as "$NEWNAME" NEWNAME=$(echo $FILE|sed s/'4%3a'//) # here we do the actual work! mv -v $FILE $NEWNAME done
Hmm... well, technically you could run it all on one line like this:
but that's kind of ugly :-P
What we have here is called a shell script. What you'll probably want to do is paste the script from above into a text file. Name that text file "myrename.sh" or something easy to remember. Copy it into your ~/bin directory, or if this is a temporary project, save it in the directory where all those files live, and execute it like:
I hope that's not too confusing.
-G
for FILE in $(find . -type f -name '*4%3a*'); do NEWNAME=$(echo $FILE|sed s/'4%3a'//); mv -v $FILE $NEWNAME; done but that's kind of ugly :-P
What we have here is called a shell script. What you'll probably want to do is paste the script from above into a text file. Name that text file "myrename.sh" or something easy to remember. Copy it into your ~/bin directory, or if this is a temporary project, save it in the directory where all those files live, and execute it like:
$ sh /path/to/myrename.sh I hope that's not too confusing.
-G
•
•
Join Date: Apr 2006
Posts: 148
Reputation:
Solved Threads: 40
•
•
•
•
Hi,
I just need to know a simple command to bulk renaming.
I have hundreds of .DEB files. I want to remove 4%3a from all file names.
example :
old name :
ark-kde4_4%3a4.0.3-0ubuntu4_i386.deb
new name :
ark-kde4_4.0.3-0ubuntu4_i386.deb
I know there is a "rename" command but I don't know it's use.
Thank you
eg usage
# ./script.sh -s "4%3a" -e "" -d "*.deb" # display all files to be renamed # ./script.sh -s "4%3a" -e "" -d "*.deb" #remove -d to do actual rename
![]() |
Other Threads in the IT Professionals' Lounge Forum
- Previous Thread: Tools/methods to speed up web build process...?
- Next Thread: Targeted email marketing & its benefits
| Thread Tools | Search this Thread |
1gbit advertising advice amazon answers archive british broadband business businessprocesses career carrier censorship cern china cio collectiveintelligence connectivity consumer consumers corporateearnings datatransfer debtcollectors dictionary digg digital ebay ecommerce email employment environment facebook food government grid high-definition hottub infodelivery infotech intel internet interview ipod isp japan kindle lhc library malware marketing mit moonfruit news onlineshopping piracy piratebay pope porn program questions r&d religion remoteworking research retail security sex shopping simple skype smallbusiness smb sms socialmedia socialnetworking software softwareengineer spam speed spending startrek statistics stocks study stumbleupon survey tabletpc technology touch-screen touchscreen twitter uk videoinprint voips web webdeveloper windows words





