rename Command Examples in Linux

The rename command is a utility in Unix-like operating systems that allows you to rename multiple files at once. It is used to change the names of files and directories, and it provides a powerful and flexible way to manipulate file names.

The rename command can also be used with regular expressions, allowing you to match more complex patterns in file names and perform more sophisticated transformations. This makes it an extremely useful tool for bulk renaming of files, especially in scenarios where you need to rename a large number of files or where the names of the files have a specific pattern.

rename Command Examples

1. Rename files using simple substitutions (substitute ‘foo’ with ‘bar’ wherever found):

# rename foo bar *

2. Dry-run – display which renames would occur without performing them:

# rename -vn foo bar *

3. Do not overwrite existing files:

# rename -o foo bar *

4. Change file extensions:

# rename .ext .bak *.ext

5. Prepend “foo” to all filenames in the current directory:

# rename '' 'foo' *

6. Rename a group of increasingly numbered files zero-padding the numbers up to 3 digits:

# rename foo foo00 foo? && rename foo foo0 foo??
Related Post