Linux/Unix: Rename Directory With Spaces In Name

by on January 7, 2013 · 0 comments· LAST UPDATED January 7, 2014

in , ,

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
DifficultyEasy (rss)
Root privilegesNo
Requirementsmv
Estimated completion time1m

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

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

Recommend readings
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: ,

Previous Faq:

Next Faq: