You need to use the mv command to rename a folder under UNIX operating systems. You must have write permission for all folders.
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | None |
Time | 1m |
Syntax to rename a directory on Unix
The syntax is as follows:
mv old-folder-name new-folder-name
OR
mv /path/to/old /path/to/new
Example: Unix rename a directory command
In this example, a folder called drivers is renamed as olddrivers. Open a terminal (shell prompt) and type the following commands:
ls mv drivers oldrivers ls
OR pass the -v option to get verbose output:
ls mv -v drivers oldrivers ls
Do not prompt for confirmation before overwriting
mv -f dir1 dir2
Prompt for confirmation before overwriting
mv -i dir1 dir2
Pass the -n option to mv command to do not overwrite an existing file/dirname. The -n option overrides any previous -f or -i options:
mv -n dir1 dir2
Recommend readings
- mv(1) command man page
- mv command examples and usage
🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.
🐧 7 comments so far... add one ↓
🐧 7 comments so far... 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 |
I how do I move a file or folder into another directory? I have tried mv file.rtf ~/Documents mv ~/file.rtf ~/Documents and mv ~/file.rtf ~/Documents/ none of these work.
I would try:
mv “file.rtf” “Documents”
mv “$HOME/file.rtf” “$HOME/Documents”
~ (tilt) means that you are working in the root directory and in root directory you can not do any changes if you have not only linux as your single o.s.
so (move, rename )changes can be done in home directory only in that case.
I would like to rename all “OK-” directory to “KESZ-” For example from: OK-Brooklyn.Nine.Nine.S02E10.WEB-DL.x264.HUN-SFY I wold like to this: KESZ-Brooklyn.Nine.Nine.S02E10.WEB-DL.x264.HUN-SFY
I need some help :D
try rename command instead.
nice appoarch
For some reason it didn’t work with hidden folders for me. :(
mv .dir .dir2
mv: cannot move .dir to .dir2: Directory not empty