How To Rename Multiple Files In Unix With Single Command. Learn about rename command in Linux that can rename multiple files. Users can rename multiple files in Linux using wildcards, using rename command.
renames command is a wonderful command to rename multiple files at once using commandline/terminal. “rename” renames the filenames supplied according to the rule specified as the first argument. The perlexpr argument is a Perl expression which is expected to modify the $_ string in Perl for at least some of the filenames specified. If a given filename is not modified by the expression, it will not be renamed. If no filenames are given on the command line, filenames will be read via standard input.
rename [ -h|-m|-V ] [ -v ] [ -n ] [ -f ] [ -e|-E perlexpr]*|perlexpr [ files ]
For example, to rename all files matching “*.jpg” to png, we will use the rename command as rename ‘s/\.jpg$/\.png/’ *.jpg You can also use the command to translate uppercase names to lower, you’d use rename ‘y/A-Z/a-z/’ *
Let us see how to use rename command to rename all jpg files to png. You can see in the screenshot above that we have only one png file named krusader.jpg. We will use rename command to change this file to png. To do so, run the command:
rename 's/\.jpg$/\.png/' *.jpg
Now let use learn a bit about the command. The rename command has two parts. The first command argument is a perl expression that tells the system to rename the file with .jp extension to .png extension. The second command argument directs the system to rename all the files with *.jpg extension. In simple words, the first commands describes what to do and the second one tells that the same operation will be executed on all files with the specified extension.
Please note that the rename command is part of the util-linux package. You may have to install it on Ubuntu Linux Systems. To install, run the the following command:
sudo apt-get install renameutils
The rename command has many options:
- -v, -verbose
Verbose: print names of files successfully renamed.
- -n, -nono
No action: print names of files to be renamed, but don’t rename.
Over write: allow existing files to be over-written.
- -h, -help
Help: print SYNOPSIS and OPTIONS.
- -m, -man
Manual: print manual page.
- -V, -version
Version: show version number.
Expression: code to act on files name. May be repeated to build up code (like “perl -e”). If no -e, the first argument is used as code.
Statement: code to act on files name, as -e but terminated by ‘;’.