How to Change a Directory Name in Linux

Renaming a directory in Linux is one of those tasks that looks simple on the surface but opens up into a surprisingly nuanced topic once you factor in permissions, active sessions, scripting environments, and whether you're working locally or on a remote server. Here's what you actually need to know.

The Core Command: mv Is How Linux Renames Directories

Linux doesn't have a dedicated "rename" command for directories in the way some operating systems do. Instead, renaming is handled by the mv (move) command. When you move a directory to a new name within the same location, the effect is a rename.

The basic syntax is:

mv old_directory_name new_directory_name 

For example, if you have a folder called projects_old and want to rename it projects_2024:

mv projects_old projects_2024 

That's it for the straightforward case. The directory contents, permissions, and ownership all stay intact. Nothing inside is touched — only the directory's name in the filesystem changes.

Absolute vs. Relative Paths

Where things start to vary is how you reference the directory. You can use:

  • Relative paths — based on your current working directory (mv old_name new_name)
  • Absolute paths — full path from root (mv /home/user/old_name /home/user/new_name)

Using absolute paths is generally safer in scripts or when you're not certain which directory you're currently in. A wrong relative path can move a directory somewhere unintended rather than renaming it.

If you accidentally provide a destination path that already exists as a directory, mv will move the source inside the destination rather than renaming it. That's a common trap worth being aware of.

Permissions and When Renaming Fails 🔒

Renaming a directory requires write permission on the parent directory — not on the directory itself. This is a distinction Linux newcomers often miss.

If you try to rename a directory and get a Permission denied error, check:

  1. Who owns the parent directory — run ls -ld /path/to/parent
  2. Your current user — run whoami
  3. Whether you need elevated privileges — if the directory is system-owned, you'll need sudo
sudo mv /etc/old_config_dir /etc/new_config_dir 

Be careful with sudo and system directories. Renaming directories that other services depend on can break those services until their configuration is updated to reflect the new path.

Renaming Directories with Spaces or Special Characters

If a directory name includes spaces or special characters, you need to quote the name or escape the characters:

mv "my old folder" "my new folder" 

Or using escape characters:

mv my old folder my new folder 

Forgetting to handle spaces is one of the most common causes of unexpected behavior when renaming in terminal — the shell interprets unquoted spaces as argument separators.

Batch Renaming Multiple Directories

For renaming many directories at once, the basic mv command works one operation at a time. There are a few approaches for bulk operations:

MethodBest ForNotes
mv in a for loopSimple pattern-based renamesBuilt into bash, no extra install
rename command (Perl-based)Regex-based batch renamesMay need to install; syntax varies by distro
rename command (util-linux)Simpler string substitutionDifferent syntax than Perl version
Custom shell scriptsComplex logic or conditional renamesMost flexible option

The rename command has two different versions that exist across Linux distributions — the Perl-based version (common on Debian/Ubuntu) and the util-linux version (common on Fedora/CentOS/RHEL). They have different syntax, so always check which version you have with rename --version before writing scripts around it.

Renaming Directories That Are Currently in Use

Renaming a directory that has active processes running inside it is technically possible on Linux — the filesystem allows it — but it can cause problems. Running processes hold references to file descriptors and paths. After the rename, those processes may fail to find expected paths, or new processes may not know where to look.

Common scenarios where this matters:

  • Web server document roots — renaming without updating the server config breaks the site
  • Running application data directories — databases, logs, and sockets may be affected
  • Symlinked paths — if other directories symlink to the renamed directory, those symlinks break immediately

Checking for active use with lsof +D /path/to/directory before renaming is a useful precaution in production environments.

Renaming on Remote Servers via SSH

When working over SSH, the mv command works identically to local use. However, terminal disconnection mid-operation is a real risk for slower filesystems or network volumes. For sensitive renames on remote servers, using tmux or screen to keep your session alive is a common safeguard.

For renaming directories on network-attached storage (NAS) or SFTP shares, tools like lftp or GUI clients (FileZilla, Nautilus with SFTP) handle the operation differently than local filesystem commands, and speed or permission behavior may vary. 🖧

The Variable That Changes Everything

Renaming a directory in a personal home folder is a five-second task. Renaming a directory on a production server, inside a containerized application, or in a path referenced by a dozen configuration files is an operation that deserves planning.

The same mv command sits at the center of both scenarios — what differs is the blast radius of getting it wrong, which depends entirely on your environment, what depends on that directory, and how tightly your system's configuration is coupled to specific path names. That's the piece no general guide can assess for you.