There are two scenarios when renaming files and folders. Either you’re renaming a single file or folder, or you want to rename many files or folders at once. Just like Windows or Mac, Linux has several ways you can do either.

Rename a Single File or Directory in Linux Using File Manager

Most distributions, or distros, of Linux have a graphical file manager similar to File Explorer in Windows or Finder in MacOS. Most of them will function in the same way, but there may be differences.

Rename Using Rename

Rename Using File Properties

This method is odd and you’re unlikely to use it, but it’s still possible. 

Rename Many Files or Folders in Linux Using File Manager

This feature may not be available in all the file managers available in the different distros of Linux. This is in PopOS.

Rename using a template allows you to do things like sequentially number files and folders or add text to the front, back, or both sides of the original filename. 

It can apply the template to the files based on the original name or modified date.

Find and replace text allows searching out a specific sequence of text and replacing it with something else. This is great for correcting spelling mistakes.

Get Help in Linux

There are a lot of ways to use the commands and utilities below. If you’re not sure what you need to do, ender the command man (for manual) and the command or name of the utility you need help with. For example, man mv will show the manual for using the mv command. After renaming files or directories in Linux, always check them by either looking in the File Explorer or using the ls command to list them.

Rename a Single File or Folder with the MV Command

The MV command is for moving files and folders, yet it works well for renaming too. The syntax for the MV command is: mv [OPTIONS] source destination Type in mv “01-Work Documents” “Work Documents” and press enter. Listing the files shows it’s renamed.

Rename Multiple Files or Folders Using Bash Script

To create a bash script, you need to work in a plain text editor. Let’s say we had several HTML files that we accidentally saved as plain text files. We need to change the file extension from .txt to .html. We can use this bash script to rename them: for file in .txt; do  mv — “$file” “${file%.txt}.html”done How did that work? The first line is looking for any file that ends in .txt. The asterisk () is a wildcard, so anything before .txt in a filename will match. The do tells it to do the command as long as there are matching files. This is a loop. The second line has the mv command.  The double-dash (—) tells it there are no options for the command, get ready for some regular expression or regex. The $file is a variable that tells it to work with any file picked up by the first line. The % tells it to replace the .txt if it’s at the tail of the name with the value outside the curly bracket, which is .html.

How to Safely Rename Files and Folders with Linux Utilities

The rest of the article is about utilities used in the Linux shell. It can be easy to make a mistake and rename critical files that may stop programs or Linux from working. Always use the -n option. It tells the command to not overwrite an existing file.  Using it in a utility command may look like: mmv -n “*” “#l1”. See below how it shows a preview of what the command will do. Yet if you list (ls) the files you’ll see none of them have changed. If it’s not what you were expecting, adjust your command and try again. 

Rename Multiple Files and Folders with Rename

Rename is a Linux utility. Think of it as a small program that doesn’t have a graphical user interface. Your Linux distro might not have it, but it’s easy to install. In the terminal, enter the command sudo apt-get install rename and press Enter. It may ask for your password, enter it, and press Enter. It will start installing. Once installed, you can start using Rename.  If you guessed that will change the file extensions on our files back to .txt from .html, you’re right!

Rename Files and Folders Using MMV

MMV is another Linux utility, similar to Rename. It can be installed with the command sudo apt install mmv. Once it’s installed, you can create your own commands. 

Is That All the Ways to Rename Directories and Files in Linux?

If one of the methods here doesn’t work for you, you could use a bulk renaming tool that has a graphical user interface.  There are several to choose from. Thunar and KRename are just a couple to start with.

How to Rename Files and Folders in Linux - 78How to Rename Files and Folders in Linux - 13How to Rename Files and Folders in Linux - 70How to Rename Files and Folders in Linux - 22How to Rename Files and Folders in Linux - 94How to Rename Files and Folders in Linux - 78How to Rename Files and Folders in Linux - 12How to Rename Files and Folders in Linux - 92How to Rename Files and Folders in Linux - 31How to Rename Files and Folders in Linux - 32How to Rename Files and Folders in Linux - 88How to Rename Files and Folders in Linux - 42How to Rename Files and Folders in Linux - 43How to Rename Files and Folders in Linux - 9How to Rename Files and Folders in Linux - 28How to Rename Files and Folders in Linux - 22How to Rename Files and Folders in Linux - 77How to Rename Files and Folders in Linux - 42How to Rename Files and Folders in Linux - 8How to Rename Files and Folders in Linux - 20How to Rename Files and Folders in Linux - 69How to Rename Files and Folders in Linux - 98How to Rename Files and Folders in Linux - 89How to Rename Files and Folders in Linux - 84