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
Click on rename optionUse 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:
mv commandHere:
- 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
Renames the folder project_old to project_newb)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
Rename files or folders in Linux by replacing a specified pattern in their namesFor 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
Installing the renameWhy 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
escalated privilegesExample:
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_name
rm -r old_folder_name # Deletes the original old_folder_name
Showing the processNote: 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:
Searches for files and directoriesThis 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
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:
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
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:
- Put the folder name within double quotes (") or single quotes ('),
- 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.
Similar Reads
How to Rename a Group in Linux?
Renaming a group in a Linux system is a straightforward but essential administrative task. If you're reorganizing your user management structure or enhancing security measures, this quick guide will walk you through the simple steps to rename a group. Linux provides a powerful command, 'groupmod' to
4 min read
How to Run a File in Linux
The command line is one of the most powerful tools in Linux. It allows you to execute commands, manage files, and automate tasks all from a single terminal window. One common task you'll often need to do is run a file, whether itâs a script, a compiled program, or even a text file. In this article,
6 min read
How to Open a File in Linuxâ
In Linux, a file is a fundamental unit of storage, representing everything from documents and images to system logs and program data. Unlike traditional operating systems, Linux treats almost everythingâfiles, directories, devices, and processesâas a file. Whether you're accessing a simple text docu
6 min read
How to Rename File in Linux | rename Command
Changing the names of files in Linux is something we often do, and the "rename" command is like a helpful friend for this job. This guide is like a journey to becoming really good at renaming files on Linux, showing you how handy and useful the "rename" command can be. Whether you're just starting o
8 min read
How to Remove Directory in Linux
In Linux, directories are used to organize files and other directories into a hierarchical structure. Just like folders in Windows, directories in Linux can contain files, other directories, and links. Removing directories in Linux is a common task that you might need to perform as you manage files
5 min read
How to Rename a Column in MySQL?
Renaming columns in MySQL is a frequent task to keep data organized and flexible. It helps adjust database layouts to fit new needs without losing information. This article will show you different ways to rename columns in MySQL, making it easier to manage and update your database structure as your
4 min read
How to Rename a Column in PL/SQL?
Renaming a column in PL/SQL is a fundamental operation in Oracle Database management. It enhances clarity, maintains consistency, or accommodates evolving data requirements. Database administrators can ensure the data integrity and process of streamlining data manipulation by altering the column nam
4 min read
How to Move File in Linux | mv Command
The `mv` command in Linux is like a superhero tool that can do a bunch of cool stuff with your files and folders. Think of it as a digital moving truck that helps you shift things around in your computer. Whether you want to tidy up your folders, give your files new names, or send them to different
7 min read
How to Rename Files in MacOS?
Renaming files in MacOS is a simple yet essential task that can help you stay organized and improve your workflow. Whether you need to rename a single file or multiple files at once, MacOS offers several easy methods to get the job done. In this guide, we will provide step-by-step instructions on ho
4 min read
How to Rename Fields in MongoDB
The $rename operator in MongoDB is a powerful tool used to rename field names within documents. It works by unsetting the old field name and setting the new one by preserving the document's atomicity but altering the field order. This operator is essential for managing and updating document structur
5 min read