Knowledgebase

How to Rename a Folder in Linux​?

When working with Linux, whether you’re managing files, organizing projects, or cleaning up your servers, renaming folders is something you will need to do quite often. It might sound like a basic task, but if you are new to the command line, it can feel a little confusing at first.

The good news is that renaming folders in Linux is extremely easy once you understand the right command and how it works!

In this guide, we will walk you through the simplest, most commonly used method for renaming a directory in the terminal. We will also explain important things to keep in mind so you don’t run into errors.

Let’s get started!


Also Read: How to Check Memory in Linux?


Method 1: Rename a Folder Using the mv Command

Linux does not have a dedicated ‘rename’ command for directories. Instead, the mv (move) command is used to rename files and folders. You simply ‘move’ a folder from its old name to a new name.

➔ To begin, open your terminal window.

➔ Use the cd command to navigate to the directory where your folder exists.

Copied!
cd /path/to/your/folder

For example, if the folder is inside your Documents:

Copied!
cd ~/Documents

➔ Now, you have to use the mv command with this basic syntax.

Copied!
mv old_folder_name new_folder_name

For example, if you want to rename a folder from project1 to project-final, run:

Copied!
mv project1 project-final

This will instantly rename the folder in the same location.


Also Read: How to Check OS Version in Linux​?


Method 2: Rename a Folder from Any Location (Using Full Path)

If you are not inside the folder’s directory, you can still rename it using full paths.

Copied!
mv /home/user/old-folder /home/user/new-folder

This is useful when you want to rename a folder without switching directories.


Also Read: How to Check OS Kernel Version in Linux​?


Method 3: Rename Multiple Folders Using Wildcards (Advanced)

If you have multiple folders with similar names and want to rename them in a pattern, you can use a loop.

For Example, add a prefix to all folders starting with ‘test’:

Copied!
for d in test*; do mv “$d” “new-$d”; done

Use this only if you are comfortable with the command line to avoid accidental changes.

Common Errors & How to Avoid Them

1. ‘No such file or directory’

This means the old folder name is incorrect or misspelled.

Use this command to check:

Copied!
ls

2. ‘Permission denied’

You may need elevated permissions.

Try adding sudo:

Copied!
sudo mv oldname newname

3. Spaces in Folder Names

If your folder name has spaces, wrap it in quotes:

Copied!
mv “Old Folder” “New Folder Name”

Also Read: How to Search a File in Linux Using a Command?


Conclusion

Renaming a folder in Linux is simple once you know the right command. The mv command, which is often labeled “move,” can also rename directories.

Whether you are organizing files, cleaning up project structures, or updating naming conventions, this method will help you do it quickly and efficiently.

With just a few commands and a little practice, you will be managing files like a Linux pro!