Created
May 11, 2010 22:43
-
-
Save alobato/397988 to your computer and use it in GitHub Desktop.
Rename multiple files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rename multiple files | |
# http://www.24hourapps.com/2009/03/linux-tips-10-rename-multiple-files.html | |
# Renaming multiple files in Linux is surprisingly difficult given the simplistic power | |
# provided by many other system commands. Unlike DOS, which provided a rename command that | |
# allowed wild cards, Linux's rename/mv command is less versatile. Therefore to rename files one needs to write a loop. Luckily bash helps a lot here. | |
# Lets say we have in our directory a number of .txt files that we need to rename to .nfo. | |
# To do this we would need to use the command: | |
for f in *.txt; do mv "${f}" "${f/.txt/.nfo}"; done; | |
# It is quite a long command, but it basically executes a loop and tells it to take each f file | |
# name in *.txt and give it a name where a match for .txt is replaced with .nfo. While I have | |
# not tried more complex patterns it should be possible to use any regular expression. Please | |
# note that the above code only does one replacement. If multiple is needed then two slashes are | |
# required after f, ie. {$f//.txt/.nfo} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment