Skip to content
-
Subscribe to our newsletter & never miss our best posts. Subscribe Now!
  • https://www.facebook.com/
  • https://twitter.com/
  • https://t.me/
  • https://www.instagram.com/
  • https://youtube.com/
https://pctechmag.co.uk/ PC Tech Mag

Tech news, gadget reviews, tips, and digital trends — PC Tech Mag keeps you informed on everything technology.

https://pctechmag.co.uk/ PC Tech Mag

Tech news, gadget reviews, tips, and digital trends — PC Tech Mag keeps you informed on everything technology.

  • Home
  • About us
  • Contact us
  • Tech

About This Site

PC Tech Mag is an online tech magazine with PC hardware and gaming guides, Windows tips, software explainers and gadget coverage.

Recent Posts

  • How to Find Duplicates in Google Sheets: 5 Easy Methods
  • How to Add Speaker Notes in PowerPoint: A Step-by-Step Guide
  • Lighter Linux: The Best Lightweight Linux Distros for Old and Slow PCs
  • Ubuntu vs Mint: Which Linux Distro Should You Choose in 2026?
  • How Do I Send a GIF in a Text Message? A Complete Guide for iPhone and Android

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Find Us

Contact: farmanali5starseo@gmail.com

  • Home
  • About us
  • Contact us
  • Tech
Subscribe
Close

Search

A Linux terminal window on a monitor showing ls and mv command-line text on a dark screen
Tech

How to Rename a Directory in Linux: mv, rename, and GUI Methods

By admin
November 3, 2026 6 Min Read
1

Learning how to rename a directory in Linux is one of the first skills every terminal user needs. Whether you are tidying a home folder, fixing a project name, or preparing files for a server, the right command can save you from copying gigabytes of data by mistake. The good news is that renaming a folder in Linux is fast, safe when you follow a few checks, and possible with or without a graphical interface.

In this guide, you will learn the standard mv command, how to rename many folders at once with rename, and how to do the same job in a file manager. You will also see a worked example, a comparison table, and fixes for the most common errors. If you are unsure which distribution you are running, first see how to check your Ubuntu version.

What Actually Happens When You Rename a Directory?

On Linux, renaming a directory does not usually copy its contents. It changes the directory entry in its parent folder, so the folder keeps the same files, permissions, and, in most cases, the same location on disk. That is why renaming is almost instant, even for a folder containing thousands of files.

This is also why the main command for renaming is called mv, short for move. Moving a folder to a new name in the same location is a rename. Moving it to a different location is a move. The command is the same; only the destination changes. A rename does not compress or archive anything, unlike creating a TAR file, and it does not change the files inside.

Before You Rename: Three Quick Checks

Before you run any command, take a few seconds to avoid the two classic mistakes: renaming the wrong folder, or overwriting an existing one.

  • Confirm where you are with pwd and list the contents with ls.
  • Check the exact spelling, including capital letters. Linux folder names are case-sensitive, so Photos and photos are different folders.
  • Check whether the new name is already in use. If it is, mv may move your folder inside it instead of renaming it.
  • Avoid spaces at the start of a name, and use underscores or hyphens instead of spaces where possible.

Method 1: Rename a Directory With the mv Command

The mv command is available on almost every Linux distribution, including Ubuntu, Debian, Fedora, and Arch. Its basic syntax is simple:

mv old_name new_name

For example, to rename a folder called project-old to project-new in the current directory, run:

mv project-old project-new

Rename a directory in the same folder

If you are already in the parent folder, you only need the two names. Use ls after the command to confirm the change. Adding the -v option makes mv print what it did, which is useful when you are learning:

mv -v project-old project-new

Rename using a full path

You do not have to change into the folder first. Give the full path to both the old and new names:

mv /home/user/Documents/notes /home/user/Documents/meeting-notes

Relative paths work too. From your home folder, mv Documents/notes Documents/meeting-notes does the same job. Use tab completion to avoid typing long paths by hand, and double-check the path before pressing Enter.

Rename and move at the same time

To move a folder and give it a new name in one step, put the new location and name as the destination:

mv /home/user/projects/draft /home/user/archive/draft-2026

If the destination folder already exists, mv will move the source inside it instead. To be asked before overwriting, use the interactive option mv -i old_name new_name. To avoid overwriting an existing folder entirely, use mv -n old_name new_name.

Method 2: Rename Multiple Directories With the rename Command

The mv command handles one folder at a time. If you need to rename dozens of folders, the rename command can apply a pattern to all of them. Note that there are two versions of rename in common use, and their syntax differs, so check your version first with rename --version or man rename.

On Ubuntu and Debian, the Perl version is common. It uses a search-and-replace expression. For example, to replace draft with final in every folder name in the current directory, you could run:

rename 's/draft/final/' draft*

On some other distributions, the util-linux version uses a simpler form, rename old new files. Always test first with a dry run where available, or try the pattern on copies of a few folders. Bulk renaming is powerful, but a wrong pattern can rename far more than you intended, and undoing it can be slow.

Method 3: Rename a Directory in a GUI File Manager

If you prefer not to use the terminal, every major Linux desktop has a file manager that can rename a folder in seconds. In GNOME Files (Nautilus), open the folder that contains the directory, right-click the folder, choose Rename, type the new name, and press Enter or click Rename. In KDE Dolphin, the steps are similar: right-click, choose Rename, or press F2 with the folder selected.

The graphical method is best for a single, visible folder, especially if you are unsure of its exact spelling. It is less suitable for renaming many folders, for folders on a remote server, or for folders you cannot see in the file manager because of permissions. In those cases, return to the terminal.

Worked Example: Renaming a Project Folder Safely

Imagine you have a folder called website-v1 in your Documents folder, and you want to call it website-redesign. Here is a safe, step-by-step sequence:

cd ~/Documents
ls
mv -i website-v1 website-redesign
ls

The first ls confirms the old name exists. The -i option asks before overwriting anything. The second ls confirms the new name. If a program, script, or website still points to the old path, update that reference next, because Linux will not update links and shortcuts automatically. If you share a drive with Windows, it is also worth knowing the difference explained in MBR vs GPT before changing partition or drive layouts, though a simple rename does not change partitions.

Command Examples Table: Which Method Should You Use?

This table is the extra angle in this guide: it puts the three methods side by side so you can choose in seconds, rather than trying each one.

MethodExample commandWhen to use it
mv commandmv old_name new_nameOne folder, terminal or server, fastest and most universal
rename commandrename ‘s/old/new/’ old*Many folders at once, following a clear pattern
GUI file managerRight-click, then RenameOne visible folder on a desktop, no terminal needed

Common Errors and How to Fix Them

“No such file or directory”

This usually means you are in the wrong folder, or the name is spelled differently. Run pwd and ls to check. Remember that Linux is case-sensitive, and that a trailing slash or a missing character matters.

“Permission denied”

You need write permission in the parent folder, not just inside the folder itself. If you own the folder, check its permissions with ls -ld folder_name. Do not reach for sudo automatically. Only use it for system folders you are authorised to change, and double-check the command first, because a mistake with elevated rights can affect the whole system.

The folder disappeared into another folder

If the destination already existed as a folder, mv moved your folder inside it. For example, mv notes archive will put notes inside archive if archive already exists. Move it back with mv archive/notes notes, then rename it with a destination name that does not already exist.

“Directory not empty” or a device error

Renaming across different drives or filesystems is a copy, not a simple rename, and it can fail if the destination is full or read-only. Check free space with df -h and, if needed, copy first, verify the copy, and only then remove the original.

Best Practices for Folder Names in Linux

  • Use lowercase letters, numbers, hyphens, and underscores for predictable results in scripts.
  • Keep names short but descriptive, so ls output stays readable.
  • Avoid leading hyphens, which can be mistaken for command options.
  • If a name contains spaces, quote it, as in mv "my folder" "my-folder".
  • After renaming, test any scripts, backups, or shortcuts that used the old path.

Frequently Asked Questions

What is the command to rename a directory in Linux?

Use mv old_name new_name. It is built into almost every Linux system and works for a single folder.

Can I rename a directory without the terminal?

Yes. In Files or Dolphin, right-click the folder, choose Rename, type the new name, and press Enter.

Does renaming a folder delete its files?

No. A rename in the same location only changes the folder name, and its files stay intact.

How do I rename many directories at once?

Use the rename command with a pattern, but test it carefully first, because it can change many names at once.

Why did mv move my folder instead of renaming it?

The destination name already existed as a folder, so mv moved the source inside it. Move it back and choose a new name that is not already in use.

Conclusion

To rename a directory in Linux, start with mv old_name new_name, use rename for bulk changes, and use your file manager for a quick visual rename. Check your location, spelling, and destination first, and use -i when you want a safety prompt. With those habits, renaming a folder becomes a routine task, not a risky one.

Author

admin

Follow Me
Other Articles
Linux terminal listing hidden files with ls -a — show hidden files in linux
Previous

How to Show Hidden Files in Linux (Terminal and File Manager)

Friends chatting online with headsets while using blogging and community platforms, illustrating LiveJournal alternatives for journaling and online blogging
Next

10 Best Discord Alternatives for Gaming, Work and Communities in 2026

One Comment
  1. How to Check Python Version on Windows, Mac and Linux - PC Tech Mag says:
    November 9, 2026 at 5:53 am

    […] you work on Linux, the same terminal skills help in other jobs too: our guide to how to rename a directory in Linux covers the basic commands you will use alongside Python every […]

    Reply

Leave a Reply Cancel reply

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

About This Site

PC Tech Mag is an online tech magazine with PC hardware and gaming guides, Windows tips, software explainers and gadget coverage.

Search

Recent Posts

  • How to Find Duplicates in Google Sheets: 5 Easy Methods
  • How to Add Speaker Notes in PowerPoint: A Step-by-Step Guide
  • Lighter Linux: The Best Lightweight Linux Distros for Old and Slow PCs
  • Ubuntu vs Mint: Which Linux Distro Should You Choose in 2026?
  • How Do I Send a GIF in a Text Message? A Complete Guide for iPhone and Android

Find Us

Contact: farmanali5starseo@gmail.com

About This Site

PC Tech Mag is an online tech magazine with PC hardware and gaming guides, Windows tips, software explainers and gadget coverage.

Recent Posts

  • How to Find Duplicates in Google Sheets: 5 Easy Methods
  • How to Add Speaker Notes in PowerPoint: A Step-by-Step Guide
  • Lighter Linux: The Best Lightweight Linux Distros for Old and Slow PCs
  • Ubuntu vs Mint: Which Linux Distro Should You Choose in 2026?
  • How Do I Send a GIF in a Text Message? A Complete Guide for iPhone and Android

Archives

  • December 2026 (15)
  • November 2026 (192)
  • October 2026 (85)

Find Us

Contact: farmanali5starseo@gmail.com

Copyright 2026 — PC Tech Mag. All rights reserved. Blogsy WordPress Theme