Rename Files and Directories in Linux

29/12/2020
Chưa phân loại
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.

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

$ mv test.txt test2.txt

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

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/.

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.

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

$ ls

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.

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

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

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.

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

Your desired file or directory should be renamed.

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.

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.

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.

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.

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.

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

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.

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

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

The files and directories should be renamed as you wanted.

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.

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

The file or directory should be renamed.

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

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Git – Push Changes to Remote Git Branch

In this article, I am going to show you how to push (upload) your local Git repository to a remote Git repository hosted...
29/12/2020

Elasticsearch Best Practices and Increasing Performance

In this post, we will try to collect best practices and also what things to avoid when working with Elasticsearch and feeding...
28/12/2020

Top list of computer forensics software

The last article was an introduction to computer forensics explaining it’s most usual practices. This article is...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

mua Proxy riêng ở đâu, và nó đem lại lợi ích gì cho người sử dụng
22/11/2022

Hướng dẫn sử dụng Proxy Helper Fakeip khi thuê proxy
21/11/2022

PROXY NUÔI TÀI KHOẢN FACEBOOK – KINH NGHIỆM FAKE IP – THUÊ PROXY GIÁ RẺ
14/11/2022

Mua Proxy Nuôi Zalo Giá Rẻ Tại Onet.com.vn
14/11/2022

BẢNG GIÁ MUA PROXY VIỆT NAM và PROXY US Onet.com.vn
14/11/2022