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

Disabling root ssh on Debian

Since the root user is universal for all Linux and Unix systems it was always the preferred bruteforce victim by hackers...
29/12/2020

Mua proxy Việt Nam giá rẻ, tốc độ cao, private, uy tín và chất lượng

MUA PROXY VIỆT NAM GIÁ RẺ   DỊCH VỤ THUÊ PROXY PRIVATE DEDICATED ONET IDC cung cấp dịch vụ IP...
09/11/2022

Mua thuê proxy v4 nuôi zalo chất lượng cao, kinh nghiệm tránh quét tài khoản zalo

Thuê proxy ipv4 IPv4 Chất Lượng Cao Tại ONET.COM.VN: Tránh Quét Tài Khoản Zalo Và Đảm Bảo An Toàn Trên...
02/01/2024
Bài Viết

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

Reliable IPv4 and IPv6 Subnet Rental Services: The Perfect Solution for Global Businesses
23/12/2024

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024