Linux provides the
rename command in order to rename the file and mo them between directories. One of the advantages of the rename command is existing links to the file are not broken or unaffected. One of the most powerful features of the rename command is the ability to rename multiple files. In order to work with the rename command, the source file names and destination filenames should be expressed with the regular expression.
rename Command Syntax
rename command has the following syntax.
rename SOURCE_REGEX DESTINATION
- SOURCE_REGEX is the source file’s regular expression to match the file name.
- DESTINATION is the destination file name.
Rename Multiple Files
In the following example, we change all files whose names start with the “db” into the “data”.
$ rename 's/\^db/data/' *
Rename Multiple Files with Specific Extension
We can rename multiple files with a specific extension. The extension is provided after the substitution expressions. In the following example, we change the names of the files with the
$ rename 's/\^db/data/' *.bak
Change Files Names To Lower Case
We can use the rename command in order to change all letters in the file name into lowercase.
$ rename 'y/A-Z/a-z/' *
Change Files Names To Upper Case
We can use the rename command in order to change all letters in the file name into uppercase.
$ rename 'y/a-z/A-Z/' *