Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have got the directory /home/user/foo and I want to rename it to /home/user/bar. How can I do this in a terminal?

share|improve this question
    
See also: How to move a directory –  kenorb yesterday

4 Answers 4

up vote 99 down vote accepted
mv /home/user/oldname /home/user/newname
share|improve this answer
3  
Related brighthub.com/computing/linux/articles/20667.aspx –  N.N. Aug 8 '11 at 17:23
    
Cool article. That's exactly the point. –  Rafał Cieślak Aug 9 '11 at 9:02
5  
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 at 4:56

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

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

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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