Rename a Directory in Linux: 3 Methods

Different Ways To Rename A Directory In Linux

You run ls, see old_project, and you want it to be new_project without touching the files inside. Linux has no standalone rename step for directories, so you reuse the move operation with a new name, which means a single mv call does the rename in place.

How renaming works on Linux

Renaming a directory does not copy data. The filesystem keeps the same inode and just updates the name entry in the parent directory, so it is instant even for large folders. The mv command handles this, because mv can either relocate a path or give it a new name in the same parent.

If you give mv two names in the same parent and the destination does not exist, it renames. If the destination already exists, mv treats the source as something to move inside the destination, which is the most common surprise when a rename seems to do nothing.

ConditionWhat mv does
Destination missingRenames in place, same inode
Destination is a directoryMoves source inside it
Destination is a file with -nSkips, keeps existing file

Method 1: Rename a single directory with mv

You will use this method daily. It works on every distribution, needs no extra package, and preserves permissions and contents. I verified the sequence below on Ubuntu 24.04 with GNU coreutils 9.4 and it behaved exactly as described.

mkdir -p old_project
touch old_project/file.txt
ls -ld old_project
mv old_project new_project
ls -ld new_project
ls new_project

The opening lines create a small test folder so you can see the effect. The mv line renames old_project to new_project in the same directory, and the final ls confirms file.txt is still inside new_project.

Terminal showing mv renaming old_project to new_project with ls verification
Renaming old_project to new_project with mv
mkdir -p /tmp/demo
mv new_project /tmp/demo/final_project
ls -R /tmp/demo

You can rename and move in one step. When either path includes a directory component, mv treats the last segment as the new name. Use an absolute or relative path for the destination and mv does the same inode rename across the filesystem when both paths are on the same partition.

mv -v old_name new_name

Add -v when you want confirmation. mv -v prints renamed ‘old_name’ -> ‘new_name’, which helps in scripts and when you chain commands. Use -i to prompt before overwriting and -n to never clobber an existing name.

Terminal showing mv -v verbose output
Verbose confirmation from mv -v
mv -i old_project new_project
# prompt: mv: overwrite 'new_project'?
mv -n old_project new_project
echo $?

The safe habit is mv -n in automated scripts and mv -i interactively. With -n a collision silently keeps the existing destination and returns 0, so check existence first when the rename must succeed.

Edge cases that catch beginners

Two edge cases produce almost all bug reports. First, names with spaces must be quoted or the shell splits them into separate arguments. Second, renaming onto an existing directory does not replace it, it nests the source inside.

mkdir -p "my old dir"
mv "my old dir" "my new dir"
ls -ld "my new dir"

Quotes keep the two words as one path. Without them mv receives three arguments and complains about a missing destination.

mkdir -p src && touch src/a
mkdir -p dst && touch dst/b
mv src dst
ls -R .
# result: dst/src/a  and  dst/b  — src moved inside dst instead of replacing it

This is intended behavior. When dst exists, mv moves src into dst. If you wanted a true replacement, remove or rename dst first, or use mv -T to treat the destination as a normal file and fail cleanly when it is a directory.

Terminal showing mv moving source inside existing destination
Edge case: mv with existing destination nests instead of renaming
mv -T src dst 2>&1
# when dst is a directory: mv: cannot move 'src' to 'dst'

Permission is the third edge. You need write permission on the parent directory, not on the directory itself, because you are editing the parent’s name table. When the parent is owned by root, prefix with sudo.

ls -ld /var/log/myapp
sudo mv /var/log/myapp /var/log/myapp.old
ls -ld /var/log/myapp.old
FlagBehavior
-vPrint what was renamed
-iPrompt before overwrite
-nNever overwrite, skip instead
-TTreat destination as file, not directory

Method 2: Bulk rename with the rename command

mv handles one directory at a time. When you need to rename many directories by prefix, the Perl rename command is the right tool. It is not installed by default on Ubuntu 24.04, which I confirmed with which rename returning no result, but it is a small apt install when you need it.

sudo apt update && sudo apt install rename
rename --version

On Debian and Ubuntu rename is the Perl version that takes a Perl expression. There is also a util-linux rename with different syntax on some systems, so check rename –version after installing to know which one you have.

mkdir -p demo && cd demo
mkdir project_01 project_02 project_03
ls
rename 's/project_/archive_/' project_*
ls

The expression s/project_/archive_/ substitutes the prefix for every match. With -n you can preview: rename -n ‘s/project_/archive_/’ project_* lists what would change without touching the filesystem, which is how I dry-run bulk renames.

rename -n 's/project_/archive_/' project_*
rename 'y/A-Z/a-z/' *
ls

The second example lowercases every name. For directories that contain files, rename acts on the directory entry itself, so contents stay intact. Always run with -n first, because a broad regex can touch more than you intended.

If you prefer no extra install, a shell loop with mv does the same job and is easier to audit.

for d in project_*; do mv -v "$d" "archive_${d#project_}"; done
ls

The loop visits each directory, strips the prefix with ${d#project_}, and renames one by one. It is verbose on purpose so you see each move.

Method 3: Rename from the file manager and bulk GUI tools

For a single directory the desktop is fastest. Open your file manager, which is Nautilus on GNOME, Dolphin on KDE, Nemo on Cinnamon, Thunar on Xfce, or Caja on MATE, right click the folder and choose Rename or press F2, type the new name and press Enter.

Nautilus and Dolphin also support bulk rename from the GUI: select multiple folders, right click, and use Rename to apply a find-and-replace or numbered sequence such as Folder001, Folder002 without touching the terminal. If your manager lacks that, GPrename remains a lightweight choice.

# Debian and Ubuntu
sudo apt update && sudo apt install gprename

# Fedora
sudo dnf install gprename

# Arch
sudo pacman -S gprename

GPrename shows a table of names, lets you find and replace, insert, or number them, and applies the renames atomically. I keep it installed on desktops where non-technical teammates need to clean up exports, because it previews every change before writing.

GUI toolBulk support
NautilusYes, Rename with find/replace
DolphinYes, inline batch rename
GPrenameYes, regex and numbering

Which method should you choose

TaskBest methodWhy
Rename one directorymv old newInstant, always available, preserves contents
Rename and relocatemv old /path/newOne call for move plus rename
Rename many at oncerename with -n previewRegex does in one line what a loop would do in several
No extra packagesfor loop with mvAuditable, no install, works over SSH
One-off on desktopFile manager F2Fastest when you already have the window open

Summary

Renaming a directory on Linux is moving it to a new name in the same parent. Use mv for single renames, add -v or -n for safety, quote names with spaces, and watch the existing-destination nesting behavior. For bulk work use rename with a -n preview or a small mv loop, and for desktop work use your file manager or GPrename.

If you just want to fix one name right now, run mv old_project new_project and verify with ls. For a cleanup by prefix, install rename, preview with -n, then run the same line without -n and verify the listing.

  • Confirm with ls -ld new_name that the rename landed
  • Run rename -n first, then remove -n to apply
  • Quote any name with spaces and check parent write permission

References

Can mv rename a directory without moving its contents?

Yes. mv old_name new_name only changes the directory entry in its parent folder. The inode and all files inside stay untouched, so the operation is instant even for large directories.

Why does mv move my directory inside another instead of renaming it?

When the destination already exists as a directory, mv treats the source as an item to move inside it. Remove or rename the destination first, or use mv -T to make the misuse fail clearly.

How do I rename directories with spaces in the name?

Quote the paths: mv “old name” “new name”. Without quotes the shell splits the name into separate arguments.

Do I need sudo to rename a directory?

You need write permission on the parent directory. For system paths like /var/log, prefix the command with sudo: sudo mv /var/log/myapp /var/log/myapp.old.

What is the difference between the two rename commands?

Debian and Ubuntu ship the Perl rename which takes a Perl expression like ‘s/old\/new\/’. Some systems ship the util-linux rename with a simpler string-replace syntax. Run rename –version to see which one you have.