You need to use the mv command to rename file or directory names on Linux or Unix-like operating systems.
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | mv |
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
Recommend readings
- mv(1) command man page
- mv command examples and usage
🐧 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |