The quickest way to rename a directory

Use the mv command to rename a directory. Type mv old-directory-name new-directory-name and press Enter. That's the entire operation — Linux treats directories the same as files when moving or renaming them.

The mv command works because renaming is technically moving a directory to a new location with a different name in the same place. If you're in the directory that contains the folder you want to rename, you can use the command exactly as shown above. If you're somewhere else, include the full path: mv /path/to/old-directory-name /path/to/new-directory-name.

The directory keeps all its contents, permissions, and timestamps. Nothing inside changes — only the folder's name on disk changes.

Key Takeaways

  • The mv command renames directories with the syntax mv old-name new-name when you're in the parent directory.
  • Include the full path if you're renaming a directory from a different location: mv /full/path/old-name /full/path/new-name.
  • You need write permission in the directory that contains the folder you're renaming, not in the folder itself.
  • The mv command works the same way whether you're renaming a directory with files inside or an empty one.

Renaming a directory you're currently inside

If you're working inside the directory you want to rename, you cannot use mv from within that directory — the shell loses track of your location once the directory name changes. Instead, move up one level first with cd .., then run the mv command.

For example, if you're inside a folder called project-old and want to rename it to project-new, type cd .. to go to the parent directory, then type mv project-old project-new. After the rename completes, you can move back in with cd project-new.

Renaming multiple directories at once

If you have several directories to rename following a pattern, you can use a loop. For instance, to rename all directories that start with backup- and end with a date to start with archive- instead, you can use a for loop with mv inside it.

A basic example: for dir in backup-*; do mv "$dir" "${dir/backup-/archive-}"; done. This command finds all directories matching the pattern backup-*, then uses string substitution to replace backup- with archive- in each name. The quotes around $dir protect directory names that contain spaces.

Test the loop with echo first if you're unsure: for dir in backup-*; do echo mv "$dir" "${dir/backup-/archive-}"; done. This shows what would happen without actually running the renames, so you can check for mistakes.

Permissions you need to rename a directory

You need write and execute permission on the parent directory that contains the folder you're renaming. You do not need write permission inside the directory itself. This is why you can rename a directory you don't own if you have the right permissions in its parent folder.

If you try to rename a directory and get a "Permission denied" error, the issue is almost always that you lack write permission in the parent directory. Check with ls -ld .. to see the parent directory's permissions. If you own the parent directory, you can add write permission with chmod u+w ... If you don't own it, you'll need the owner or an administrator to grant permission.

Renaming directories with special characters or spaces

Directory names with spaces, hyphens, or special characters work fine with mv, but you need to quote the names or escape the special characters. The safest approach is to wrap the entire path in quotes: mv "old directory name" "new directory name".

If you prefer not to use quotes, you can escape individual special characters with a backslash. For example, mv old\ directory\ name new\ directory\ name escapes each space. This becomes tedious with many special characters, so quotes are usually clearer.

Tab completion in the terminal can help here — type the first few letters of the directory name and press Tab, and the shell will complete it and add quotes or escaping automatically if needed.

What happens if the new name already exists

If a directory with the new name already exists in the same location, mv will move the old directory inside the existing one instead of renaming it. This is rarely what you want. For example, mv project-old project-new when project-new already exists will result in project-new/project-old.

To prevent this, use the -i flag: mv -i project-old project-new. This prompts you to confirm before overwriting, giving you a chance to catch the mistake. Some Linux distributions set mv to use -i by default, but it's safer to include it explicitly if you're working with important directories.

Renaming directories across different filesystems

The mv command works across different filesystems — you can move and rename a directory from one disk or partition to another in a single operation. Linux handles this transparently; you don't need to do anything different.

However, if the move is very large (hundreds of gigabytes), it may take time. The operation is atomic at the filesystem level, meaning it either completes fully or fails completely — you won't end up with a partially moved directory.

Frequently Asked Questions

Can I undo a directory rename?

No, mv doesn't create a backup or undo history. Once you rename a directory, the old name is gone. If you need to keep the old name, use cp -r old-name new-name to copy the directory first, then delete the original only after confirming the copy is complete.

Does renaming a directory break anything inside it?

No. Absolute paths inside scripts or configuration files will break, but relative paths and symlinks pointing into the directory continue to work. If you have scripts that reference the directory by its old absolute path, you'll need to update those paths manually.

What's the difference between mv and rename?

The rename command is a Perl-based tool designed specifically for batch renaming files and directories using pattern matching. The mv command is simpler and works everywhere. For single directory renames, mv is the standard choice.

Can I rename a directory I don't own?

Only if you have write permission in the parent directory. Ownership of the directory itself doesn't matter — permission on the parent folder is what controls whether you can rename it. Ask the owner or administrator to grant write permission on the parent if you need to rename someone else's directory.