To rename multiple files in Linux, you can use the rename
command. This command allows you to specify a search pattern and a replacement string, and it will rename all files that match the search pattern with the replacement string.
For example, suppose you have a directory with the following files:
1 2 3 |
file1.txt file2.txt file3.txt |
To rename all of these files so that they have the extension .bak
, you can use the following command:
1 |
rename 's/\.txt$/.bak/' * |
This command searches for files that have the .txt
extension, and replaces the .txt
with .bak
. The *
at the end of the command specifies that the command should be applied to all files in the current directory.
You can also use the rename
command to perform more complex renaming operations. For example, you can use regular expressions to match specific patterns in the filenames and use back-references to include parts of the original filename in the replacement string.
For more information about the rename
command and how to use it, you can type man rename
at the command prompt to read the manual page for the command.