Which command do you use to rename files and directories?

You rename a directory by moving it to a different name. Use the mv command to rename directories.


$ pwd /home/user2/veggies $ ls broccoli $ mv broccoli carrots $ ls carrots

You can also use mv to move a directory to a location within another directory.


$ pwd /home/user2/veggies $ ls carrots $ mv carrots ../veggies2 $ ls ../veggies2 carrots

In this example, the directory carrots is moved from veggies to veggies2 with the mv command.

In Linux, you can rename files and directories from the command line.  You can also rename files and directories using the graphical user interface or keyboard shortcuts if you’re using a graphical desktop environment.

In this article, I will show you some of the ways to rename files and directories in Linux. So, let’s get started.

Renaming Files from the Command Line:

You can rename files from the command line in Linux using the mv command. mv stands for move. In Linux, renaming is also known as moving a file.

The format of the mv command is:

$ mv file_to_rename new_filename

For example, let’s say, I have a file test.txt which I want to rename to test2.txt.

Which command do you use to rename files and directories?

To rename the test.txt file to test2.txt, run the mv command as follows:

Which command do you use to rename files and directories?

As you can see, the file test.txt is renamed to test2.txt.

Which command do you use to rename files and directories?

Renaming Directories from the Command Line:

The same way, you can rename a directory as well.

For example, let’s say, you have a directory programming/ and now you want to rename it to codes/.

Which command do you use to rename files and directories?

To rename the directory programming/ to codes/, run the mv command as follows:

$ mv -v programming codes

NOTE: Here, the -v option is used to show the status of the command.

As you can see, the command ran successfully and the directory programming is renamed.

Which command do you use to rename files and directories?

We can further verify that the directory programming/ is renamed to codes/ using the ls command as you can see in the screenshot below.

Which command do you use to rename files and directories?

Renaming Files and Directories using Nautilus File Manager:

You can also rename files and directories graphically using the Nautilus file manager if you’re using GNOME 3 desktop environment.

To rename a file or directory, just right click (mouse click) on the file or directory and click on Rename… as marked in the screenshot below.

Which command do you use to rename files and directories?

Now, type in a new name and click on Rename or press .

Which command do you use to rename files and directories?

The selected file or directory should be renamed as you can see in the screenshot below.

Which command do you use to rename files and directories?

You can also click on a file or directory to select it and press F2 on your keyboard to rename the file or directory.

Select a file or directory and press F2.

Which command do you use to rename files and directories?

The same way, type in a new name and click on Rename or press .

Which command do you use to rename files and directories?

Your desired file or directory should be renamed.

Which command do you use to rename files and directories?

Renaming Multiples Files and Directories with Nautilus File Manager:

You can also rename multiple files together with nautilus file manager.

To do that, select the directories and files that you want to rename.

Which command do you use to rename files and directories?

Then, press F2 on your keyboard. You should see the following window. On the left side, the original file and directory names of the selected files and directories are displayed. On the right side, the file and directory names that will be after the rename operation is displayed. Right now, both of these are the same.

Which command do you use to rename files and directories?

Now, if you want to add something before the original file or directory name, then add it before the [Original file name] as marked in the screenshot below. As you can see, file and directory name after the rename operation is previewed on the right side of the window.

Which command do you use to rename files and directories?

You can also add something to the end of the file or directory name. To do that, type in what you want to add after the [Original file name] as marked in the screenshot below. The same way, a preview of what the file and directory names will be is displayed on the right side of the window.

Which command do you use to rename files and directories?

If you want, you can also add numbers to the [Original file name]. To do that, click before or after the [Original file name] depending on where you want to add numbers and click on + Add. Now, select the number format that you want to add from the list.

Which command do you use to rename files and directories?

As you can see, the file and directory names are updated on the preview (right side of the window).

Which command do you use to rename files and directories?

If you want, you can also find and replace portion of the names of files and directories. To do that, click on Find and replace text radio button.

Now, type in what you want to find within the existing name in the Existing Text section and what you want to replace it with in the Replace With section.

Which command do you use to rename files and directories?

As you can see, the matched section is highlighted and the replaced name is displayed in the preview section.

Which command do you use to rename files and directories?

Once you’re happy with the results, click on Rename.

Which command do you use to rename files and directories?

The files and directories should be renamed as you wanted.

Which command do you use to rename files and directories?

Renaming Files and Directories with Dolphin File Manager:

You can do simple rename operations with Dolphin file manager.

To rename a file or directory, right click (mouse) on it and click on Rename… as marked in the screenshot below. You can also select the file or directory and press F2 on your keyboard to do the same thing.

Which command do you use to rename files and directories?

Now, type in a new file or directory name and press .

Which command do you use to rename files and directories?

The file or directory should be renamed.

Which command do you use to rename files and directories?

So, that’s basically how you rename files and directories in Linux. Thanks for reading this article.

About the author

Which command do you use to rename files and directories?

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.

What command do you use to rename files and directories in Linux?

Renaming Files with “mv” Command A simple way to rename files in Linux is with the mv command (shortened from “move”). Its primary purpose is moving files and folders, but it can also rename them, since the act of renaming a file is interpreted by the filesystem as moving it from one name to another.

Which command should you use to rename or move a file or directory )? In Linux?

To rename a file in Linux you use the mv command. The command accepts two or more arguments. For renaming files, only two arguments are needed, which are the source file and the target file. The mv command will take the source file specified and rename it to the target file.

What is the command to rename a file in Linux?

To rename a file in the terminal, move the file with mv from itself to itself with a new name.

Which command is used to rename a file in computer?

The rename command is used to rename a single file or folder from the Command Prompt. Rename and ren can be used interchangeably. They're the exact same command.