How do I rename a directory via the command line?
mv /home/user/oldname /home/user/newname
mv
can do two jobs.
- It can move files or directories
- It can rename files or directories
To just rename a file or directory type this in Terminal:
mv old_name new_name
with space between the old and new names.
To move a file or directory type this in Terminal.
mv file_name ~/Desktop
it will move the file to the desktop.
If is a directory you should add -R
before the directory name:
mv -R directory_name ~/Desktop
mv -T /home/user/oldname /home/user/newname
That will rename the directory if the destination doesn't exist or if it exists but it's empty. Otherwise it will give you an error.
If you do this instead:
mv /home/user/oldname /home/user/newname
One of two things will happen:
- If
/home/user/newname
doesn't exist, it will rename/home/user/oldname
to/home/user/newname
- If
/home/user/newname
exists, it will move/home/user/oldname
into/home/user/newname
, i.e./home/user/newname/oldname
Source: How to decide that mv moves into a directory rather than replacing directory?
If you want to rename a directory at your level in the file system (e.g., you are at your home directory and want to rename a directory that is also in your home directory):
mv Directory ./NewNameDirectory
This gvfs-move
command will also rename files and directories.
gvfs-move /home/user/oldname /home/user/newname