Linux/Unix: Rename Directory With Spaces In Name

I have directory named My Personal Files. How do I rename folders / directory containing white space in name on Unix-like operating systems?

You need to use the mv command to rename file or directory names on Linux or Unix-like operating systems.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements mv
Est. reading time 1m

Rename Directory With Spaces

The syntax is as follows:

Syntax # 1 – Using single quotes

Enclosing directory name in single quotes ('dir name') preserves the literal value of directory name within the quotes:

mv 'old name here' 'new dir name here'

Open the Terminal and type the following command to rename “My Personal Files” to “Files”:
mv 'My Personal Files' Files
ls -l

Syntax #2 – Using escape character

A non-quoted backslash \ is the shell escape character. It preserves the literal value of the next character that follows, with the exception of newline: The syntax is:

mv old\ name\ here 'new\ dir\ name\ here'

Open the Terminal and type the following command to rename “My Personal Files” to “Files”:
mv My\ Personal\ Files Files
ls -l

Sample session

Fig.01: Bash shell mv command: Rename Files With White Spaces

Recommend readings

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum