Open In App

How to Rename a Folder in Linux

Last Updated : 20 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Renaming a folder in Linux is possible with Graphical User Interface (GUI) file managers as well as with powerful command-line utilities such as mv, rename, find, and rsync. Be it a novice utilizing Ubuntu, Debian, CentOS, Fedora, or Kali Linux or an expert dealing with bulk renaming in the terminal, Linux has more than one way of renaming directories with ease.

In this article, we provides information on how to rename a folder in Linux through GUI, command-line procedures such as mv, rename, and rsync, and how to work with permissions with the use of sudo for root folders. Batch renaming methods, renaming folders that have spaces, and renaming folders within Git repositories through git mv are also explained.

How to Rename a Folder in Linux (Command & GUI Methods)

Rename a Folder in Linux Using Graphical User Interface (GUI)

If you prefer more visual approach to Rename a Folder in linux than most Linux distributions come with file managers. Here’s how to do it using file manager

Step 1: Open the File Manager

At first open your file manager application. This could be Nautilus (GNOME Files), Dolphin (KDE), Thunar (XFCE), or any other file manager depending on your Linux distribution.

Step 2: Navigate to the Folder

After that navigate to the directory that contains the folder you want to rename.

Step 3: Rename the Folder

  • Than Right-click on the folder or Directory you want to rename.
  • Select the Rename from the context menu and add the new name in it.

Step 4: Verify the Change

You should see the folder name updated in the file manager

Screenshot-from-2025-01-02-17-24-32
Click on rename option

Use Command Line to Rename a Folder in Linux

There are various commands to rename a folder or the directory in Linux, such as the commonly used mv, the advanced rename command for batch renaming, and mv with sudo for folders requiring elevated permissions.

1. Rename a Folder with mv Command

mv (move) command : It is the simplest way to rename directories in Linux. It also allows to move files and directories within the file system

Follow these steps to rename a folder using the command line:

Step 1 : Before rename a folder in linux firstly we need to navigate to the directory that contains the folder you want to rename. Use the ` cd `(change directory) command to do this

cd ~/Documents      # It changes your directory in linux distribution

Step 2 : After navigating we need to rename a folder using the mv Command. Use the following syntax to rename a folder:

Syntax:

mv old_folder_name new_folder_name

Example:

Screenshot-from-2025-01-02-10-46-19
mv command

Here:

  • old_folder_name: The current name of the folder you want to rename.
  • new_folder_name: The new name of the folder.

Additional Use Cases for Rename a Folder in Linux

a)Rename a Folder in a Different Directory

Provide the the full or relative path to the folder.

Syntax:

mv /home/user/Documents/project_old /home/user/Documents/project_new
Screenshot-from-2025-01-02-11-04-08
Renames the folder project_old to project_new

b)Rename a Folder with Spaces in its Name

You need to use quotes or escape spaces with a backslash (\), if the folder name contains spaces or special characters, :

Using quotes:

Syntax:

mv "my folder" "new folder"

Using backslashes:

mv my\ folder new\ folder

Step 3: Verify the Folder Name Change

To confirm the folder has been renamed, list the directory contents:

ls                    # This will display the updated folder name.

2. Batch Rename a Folder in Linux Using the rename Command

`rename` command: It is used to rename multiple folders at once using the regular expressions. This method is particularly useful for batch renaming.

Syntax:

rename 's/old_pattern/new_pattern/' folder_name
Screenshot-from-2025-01-02-17-33-30
Rename files or folders in Linux by replacing a specified pattern in their names

For example: If you want to rename all folders or directories that start with "old_" to "new_", use:

rename 's/^old_/new_/' old_*
  • This command searches for all folder names starting with "old_" and renames them by replacing "old_" with "new_".
  • The ^ symbol ensures that match occurs at the beginning of the folder name.

Installing the rename Command:

If rename is not installed in your linux system than, you can install it based on your Linux distribution:

sudo apt install rename       #For Debian/Ubuntusudo yum install rename    # For CentOS/RHEL
Screenshot-from-2025-01-02-17-32-01
Installing the rename

Why Use rename Instead of mv?

  • It is ideal for renaming multiple folders in once.
  • Allows the use of regular expressions for more flexible renaming.
  • It saves the time compared because by ` mv ` command we renaming each folder individually.

3. Using `mv` with `sudo` for Root Folders to Rename a Folder in Linux

If we use the sudo command with mv than we allow the root level modification so that we can't face the permission errors

Syntax:

sudo mv old_folder_name new_folder_name
Screenshot-from-2025-01-02-17-37-27
escalated privileges

Example:

if we rename a system directory (e.g., renaming /var/www/old_site to /var/www/new_site), use:

sudo mv /var/www/old_site /var/www/new_site

4. Advanced Folder Rename in Linux Using rsync (Copy & Delete Method)

rsync: If we do the renaming process and if some especial complex scenarios comes like symbolic links or folder contents than we can use the `rsync` to copy the folder to a new name and then delete the old one.

Syntax:

rsync -a old_folder_name/ new_folder_name/              # Copies the contents of old_folder_name to new_folder_namerm -r old_folder_name                                                            # Deletes the original old_folder_name
Screenshot-from-2025-01-02-17-41-25
Showing the process

Note: The `rsync -a` command copies the folder and its contents to the new folder . Once confirmed, you can delete the old folder with `rm -r`.

Why Use rsync for Renaming?

  • When they do renaming it ensures data integrity as well
  • It preserves the file permissions, ownerships, and symbolic links also.
  • It is ideal for renaming large folders without disrupting active processes.

5. How to Rename Nested Folders in Linux Using find and rename

If you need to rename directories recursively (i.e., rename folders inside subdirectories), you can combine the find and rename commands. This method is particularly useful for batch renaming folders in deeply nested structures, making it a powerful technique for Linux directory management.

Syntax:

find /path/to/parent_directory -type d -name "old_pattern" -exec rename 's/old_pattern/new_pattern/'{} \;

Example:

If you want to rename all directories named "old_folder" to "new_folder" inside a parent directory and its subdirectories, run:

Screenshot-from-2025-01-02-17-45-18
Searches for files and directories

This will search for all directories (-type d) named old_folder and rename them to new_folder recursively.

NOTE : Ensure the rename command is installed on your system. You can install it using:

sudo apt install rename

6. Rename a Folder in Linux Using `mv` with Wildcards

You can use wildcards with the mv command to rename multiple folders at once. This method is particularly useful when you need to update folder names with a common prefix or suffix.

For example, if you want to rename project1, project2, and project3 to 2025_project1, 2025_project2, and 2025_project3, use the following command in your terminal:

Syntax:

for dir in project*; do  
mv "$dir" "2025_$dir"
done
Screenshot-from-2025-01-02-17-47-28
This command loops through all folders that start with project and renames them by adding the prefix 2025_

Why Use Wildcards for Renaming Folders in Linux?

  • Quickly rename multiple directories without manual input.
  • Saves time when working with structured folder naming.
  • Works seamlessly with automation scripts for Linux file management.

7: Rename a Folder in Linux Using rename with Perl Expressions

The`rename`command can also be used with Perl expressions for more complex renaming tasks. This is particularly useful for advanced users who want to perform sophisticated renaming operations. This is particularly useful for bulk renaming tasks, such as changing letter cases, replacing patterns, or modifying multiple directory names efficiently.

To rename folders by changing their case, you can use:

NOTE : Ensure the rename command is installed on your system. You can install it using:

sudo apt install rename

Syntax:

rename 'y/a-z/A-Z/' old_folder*

Example:

Screenshot-from-2025-01-02-17-49-28
Converts all lowercase letters in folder names matching old_folder* to uppercase.

This command will convert the names of all folders starting with old_folder from lowercase to uppercase.

8. Renaming Folders Using find and xargs

For more complex renaming scenarios, you can use `xargs` to process multiple folders.

Using `find` with `xargs`allows you to efficiently perform operations on multiple files or directories that match specific criteria. For example, to rename directories starting with old_folder to new_folder, you can use:

Syntax :

find . -type d -name "old_folder*" | xargs -I {} mv {} new_folder{}

Example : If you have multiple directories named old_folder1, old_folder2, and old_folder3, and you want to rename them to new_folder1, new_folder2, and new_folder3, the above command automates the process efficiently

Screenshot-from-2025-01-02-17-59-44
Renames multiple directories that start with "old_folder"

9. Rename a Folder in Linux Using ` git mv ` for Version-Controlled Directories

The `git mv ` command is used to rename files or directories within a Git repository while preserving version history. When you rename a directory using `git mv `, Git automatically stages the change for the next commit.

For example, to rename a directory from old_folder to new_folder, you would use:

Syntax :

git mv old_folder new_folder

This makes it simpler to handle changes over time by guaranteeing that the rename is recorded in the repository.

Why Use git mv?

  • Ensures Git history is preserved after renaming.
  • Prevents confusion when staging changes in version-controlled projects.
  • Automatically stages the rename operation for the next commit

How to Rename a Folders with Spaces in Linux

In Linux, renaming directories with spaces in their names is difficult as spaces serve as command separators. If not done properly, one may face errors or unusual results. Below is a detailed process on how to rename directories with spaces within them by using the mv command alongside possible solutions for permission problems:

Step 1: Use Quotes or Escape the Spaces

When dealing with folders that have spaces within their names, you can either:

  1. Put the folder name within double quotes (") or single quotes ('),
  2. Escape the spaces with a backslash (\).

For example:

Using quotes:

mv "Old Folder Name" "New Folder Name"

Escaping spaces:

mv Old\ Folder\ Name New\ Folder\ Name

Step 2: Verify the Folder Names

Next, you may type ls command in order to confirm the exact name of the folder you want to rename. Bear in mind that if the name consists of special characters or spaces, you have to type it exactly as it appeared on the output of ls.

Example:

ls -l                 # This helps avoid typos and ensures you're renaming the right folder.

Step 3: Rename the Folder

After this, you can rename the folder by writing the below command:

mv "Old Folder Name" "New Folder Name"

Step 4: Handle Permission Issues (If Required)

In the case where ‘Permission Denied’ error pops up, try the below command with sudo so the command is run with higher privileges:

sudo mv "Old Folder Name" "New Folder Name"

These steps ensure that folders with spaces in their names are renamed accurately without errors.

Also Read:

Conclusion

There are several methods to rename a folder in Linux and it is a crucial task that has to be understood. Every Linux user needs to enhance their skills by learning how to use the GUI components or command line tools like mv, rename, find, rsync, or git. It is possible to perform folder renaming tasks using either the command line or GUI and both methods have their own advantages.

Basic renaming can be accomplished with mv command, which is perhaps the most popular method. When batch renaming folders that contain spaces, root folders, or other folders within folders, tools such as rename, find, xargs, and rsync are much better suited for the task than mv.

These techniques allow users to rename directories swiftly and improve the organization of the file system, streamline version control on Git repositories, and so much more. One can easily carry out smooth Linux directory management on different distributions of Linux such as Debian, Ubuntu, Red Hat, Arch Linux, etc., by knowing these techniques.


Next Article
Article Tags :

Similar Reads