I have got the directory
/home/user/oldname and I want to rename it to
/home/user/newname. How can I do this in a terminal?
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:
/home/user/newnamedoesn't exist, it will rename
/home/user/newnameexists, it will move
gvfs-rename will rename directories as well. It will give an error if a directory with the new name already exists. The only limitation is that you can't use a path with the folder name. So
gvfs-rename /home/boo /home/boo-the-dog
will not work, but
cd /home gvfs-rename boo boo-the-dog
will work. Not as useful as mv -T but I read in the man that it was meant for network operations.