Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
See also: How to move a directory – kenorb Sep 19 '14 at 22:36
Use always mv or rename. – Djack Jul 1 at 20:11
up vote 303 down vote accepted
mv /home/user/oldname /home/user/newname
share|improve this answer
Cool article. That's exactly the point. – Rafał Cieślak Aug 9 '11 at 9:02
This will not work if the new name is already an existing directory. Instead, it will move the old directory inside the new one. – cxrodgers Apr 17 '14 at 4:56
If the directory name is the same with capitalization you will get No such file or directory. To avoid this do something like mv /home/user/Folder /home/user/temp; mv /home/user/temp/ /home/user/folder. – DutGRIFF Dec 5 '14 at 16:30

mv can do two jobs.

  1. It can move files or directories
  2. 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
share|improve this answer
mv on Ubuntu is from GNU coreutils. AFAICT it doesn't have a -R option, nor it is necessary when moving a directory. – arielf Sep 9 '15 at 7:46

This gvfs-move command will also rename files and directories.

gvfs-move /home/user/oldname /home/user/newname
share|improve this answer

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
share|improve this answer
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?

share|improve this answer

protected by heemayl Sep 19 '15 at 18:34

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.