Rename Multiple Files and Directories with mvdir

Dmitri Popov

Productivity Sauce

Mar 19, 2014 GMT
Dmitri Popov

Here is a problem: you need to give a bunch of DSC_xxx.JPG files meaningful names like Berlin_May_1981.JPG, Tokyo_Trip_1973.JPG, and so on. The mvdir Bash shell script dramatically simplifies this otherwise tedious task. The script scans the specified path and opens a list of all found files and directories in a default text editor. Edit then the names, and the script automatically renames the modified files and directories when you close the editor.

To install the script on your system, create a new file in a text editor, paste the code in the file, and save under the mvdir name in the /usr/local/bin directory. Make then the script executable using the chmod +x ~/usr/local/bin/mvdir command. Alternatively, you can put the script into the ~/bin directory which is automatically added to your path. If this is not the case, add the following code to the ~/.bashrc file:

if [ -d $HOME/bin ]; then

To use the script, run the mvdir path/to/dir command, where path/to/dir is the path to the directory containing the files you want to rename.

comments powered by Disqus

Issue 31: Linux Shell Handbook 9th Ed./Special Editions

Buy this issue as a PDF

Digital Issue: Price $15.99
(incl. VAT)


njobs Europe
Njobs Netherlands Njobs Deutschland Njobs United Kingdom Njobs Italia Njobs France Njobs Espana Njobs Poland
Njobs Austria Njobs Denmark Njobs Belgium Njobs Czech Republic Njobs Mexico Njobs India Njobs Colombia