41

I want to move one file to a folder using terminal. How do I do this?

57
mv [file] [directory]

For example, to move info.txt from the actual directory into the config/ directory, type mv info.txt config/


As was pointed out in a correct comment, the above will fail if the user running the command doesn't have write access to either the file or the folder.

If you prefix the command with sudo, you are telling the system to run the command as the root user (similar to an Admin account). Example:

sudo mv info.txt config/

BIG IMPORTANT NOTE:
Only use sudo if you are sure you know what you're doing - Ubuntu protects things for a reason. Using sudo you can break your OS, forcing a reinstall, if you move (or delete or whatever) important files.

  • 1
    depends on the ownership and permissions of the destination. Might need to use sudo or discuss ownership / permissions. – Panther May 14 '14 at 16:13
3

You can use the same command for renaming files. A rename is essentially moving a file to the same location but with a new name. Using the previous example:

mv info.txt config/information.txt

This would move the file and change its name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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