Javatpoint Logo
Javatpoint Logo

Linux Rename File and Directory

To rename a file there are other commands also like 'mv'. But 'rename' command is slightly advanced then others. This command will be rarely used and it works differently on different distros of linux. We'll work on Debian/Ubuntu examples.

Generally, renaming is not a big task, but when you want to rename a large group of files at once then it will be difficult to rename it with 'mv' command. In these cases, it is adviced to use 'rename' command. It can convert upper case files to lower case files and vice versa and cn overwrite files using perl expressions. This command is a part of perl script.

Basic syntax:

This ('s/old-name/new-name/') is the PCRE (perl compatible regular expression) which denotes files to rename and how.

Let's see an example of basic rename command:

In the example below we have converted all the files ending with '.txt' into files ending with '.pdf'.


In another example, we have converted file into document for all files ending with .pdf


rename option:

rename has some optional arguments but a mandatory perl expression that comes with every opption and guides it how to work.

rename -n Check changes before running the command.
rename -v Print the output.
rename (a-z)(A-Z)/ (A-Z)(a-z)Convert into upper case/lower case.
rename -f Forcefully over write existing files.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA