How to Rename a Folder in Linux in Easiest Way

Understanding Folder Renaming in Linux

In Linux, there’s no separate “rename” command.
Instead, Linux uses the mv (move) command to rename both files and directories.

That’s because, technically, renaming a folder is just like moving it from one name to another location in the same directory.

So when you do:

mv old_folder new_folder

Linux “moves” the folder to a new path which is effectively renaming it.


Basic Syntax of the mv Command

The structure is simple:

mv [options] old_name new_name
  • old_name → current folder name
  • new_name → new folder name you want to give
  • options → optional flags for more control

Example:

mv project_2024 project_backup

This changes the folder name from project_2024 to project_backup.


Rename a Folder in the Same Directory

If you’re inside the same directory, you can just run:

mv old_folder new_folder

Example:

Let’s say your folder structure looks like this:

/home/user/documents/

And you have:

old_reports/

To rename:

mv old_reports new_reports

Result:

/home/user/documents/new_reports/

Rename a Folder from Another Directory

You can also rename folders located elsewhere by providing the full path.

Example:

mv /home/user/old_folder /home/user/new_folder

This works even if you’re not currently in that directory.


Rename Multiple Folders Using Brace Expansion

If you need to rename several folders with similar names, Linux supports a handy feature called brace expansion.

Example:

Suppose you have:

project_v1, project_v2, project_v3

and you want to rename them as:

project_2023_v1, project_2023_v2, project_2023_v3

You can run:

for folder in project_v*; do mv "$folder" "${folder/v/project_2023_v}"; done

This loop renames all matching folders efficiently.


Rename Folder Using rename Command (Optional Tool)

While mv works in all systems, some Linux distributions include a dedicated rename command for advanced bulk renaming.

Syntax:

rename 's/old_text/new_text/' foldername

Example:

rename 's/old/new/' old_folder

It changes old_folder to new_folder.

Note:
The syntax may vary depending on your Linux distro.
For example, Debian-based and Red Hat–based systems use slightly different rename tools.

You can check which version you have using:

rename --version

Rename Folder Using Absolute and Relative Paths

Using Relative Path:

If you’re already in /home/user:

mv documents reports

Using Absolute Path:

You can also specify the complete paths:

mv /home/user/documents /home/user/reports

Both commands do the same thing — it’s just about where you’re currently located.


Rename Folder in Another Directory

If you’re in a different directory, you can still rename folders elsewhere.

Example:
You’re in /home, but want to rename something in /home/user/projects.

Run:

mv /home/user/projects/old_folder /home/user/projects/new_folder

No need to cd into the folder first.


Check the Folder Before and After Renaming

You can list directories before renaming:

ls

After renaming, check again:

ls

You’ll see the new folder name reflected immediately.


Rename Folder with Spaces in Its Name

If your folder has spaces (like “My Documents”), always use quotes:

mv "My Documents" "My Reports"

Without quotes, Linux will treat it as two separate names and show an error.


Rename a Folder as Root or with Sudo

If you’re renaming a system or restricted directory, you might need root permissions.

Example:

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

This ensures permission issues don’t block the rename.


Rename Multiple Folders with a Pattern (Advanced)

For more complex batch renaming, you can use the rename command or a loop.

Example:

Rename all folders starting with “test_” to “prod_”:

for folder in test_*; do mv "$folder" "${folder/test_/prod_}"; done

Each folder name gets replaced with the new prefix automatically.


Rename Folder Using GUI (Desktop Users)

If you’re using a desktop environment like Ubuntu GNOME, Fedora Workstation, or KDE, you can rename folders easily:

  1. Open your File Manager (e.g., Nautilus).
  2. Right-click the folder you want to rename.
  3. Choose “Rename” or press F2.
  4. Enter the new name and hit Enter.

Behind the scenes, it’s still using the same system logic as mv.


Verify Folder Rename

Once renamed, you can check using:

ls -ld new_folder

It shows:

drwxr-xr-x 2 user user 4096 Oct 4 12:10 new_folder

This confirms your rename worked correctly.


Common Errors and Fixes

Error MessageMeaningSolution
mv: cannot move ‘old_folder’ to ‘new_folder’: Permission deniedYou don’t have permissionUse sudo mv
mv: cannot stat ‘old_folder’: No such file or directoryThe folder name is wrong or doesn’t existDouble-check spelling with ls
mv: overwrite ‘new_folder’?The destination folder already existsUse a unique new name or remove the existing folder

Pro Tip:
If the target folder already exists, you’ll be prompted whether to overwrite it. Always check with ls first before running mv.


Example: Renaming a Project Folder

Let’s assume you have a folder structure like:

/home/pratham/projects/

And inside you have:

mywebsite_old/

You want to rename it to:

mywebsite_live/

Steps:

cd /home/pratham/projects
mv mywebsite_old mywebsite_live

Check:

ls

Output:

mywebsite_live

Done — folder renamed successfully!


Summary of Commands

TaskCommand
Basic renamemv old_folder new_folder
Rename with pathmv /path/old /path/new
Rename with spacesmv "Old Folder" "New Folder"
Rename as rootsudo mv old_folder new_folder
Rename with patternrename 's/old/new/' foldername
Bulk rename loopfor folder in old_*; do mv "$folder" "${folder/old_/new_}"; done

Wrapping Up

Renaming folders in Linux is simple once you understand the mv command.

For most situations, this is all you need:

mv old_folder new_folder

It’s fast, reliable, and works on every Linux distribution whether you’re using Ubuntu, Fedora, CentOS, or Debian.

If you’re dealing with multiple folders or want automation, try the rename command or use loops for bulk renaming.

Mastering these basics makes Linux file management much easier and more efficient.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *