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?
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.To just rename a file or directory type this in Terminal:
with space between the old and new names.
To move a file or directory type this in Terminal.
it will move the file to the desktop.
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:
One of two things will happen:
/home/user/newname
doesn't exist, it will rename/home/user/oldname
to/home/user/newname
/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):
This
gvfs-move
command will also rename files and directories.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
will not work, but
will work. Not as useful as mv -T but I read in the man that it was meant for network operations.
My preferred method is using: vidir because I love vi
Install moreutils
Call command vidir in your home-directory
Now search for the directory to change, using slash / e.g. /oldname make the changes, then press = ESC type :wq
Done!