How to Move Files in Linux mv Command

If you are wanting to know how to move files in Linux, you will need to use the Linux mv command. There are a few different options you can use with the Linux mv command, but I normally don’t use them. I do use the Linux mv command along with other commands to accomplish some tasks though. If you wanted to get information on the other options for the Linux mv command, remember you can always run man mv in a bash shell prompt.

The usage of the Linux mv command to move files around on your file system is much like the Linux cp command, but the source will no longer exist. To use the mv command in Linux shell, just run mv [source] [destination].

So for example I am making a new account on another Linux computer. I want to move my home directory to the new Linux computer. So first I setup nfs and mount my new Linux computer’s /home directory on my old Linux computer. Now I will run mv /home/max /mnt/home/ so all of my files move to my new Linux computer. This is just an example as I would most likely use rsync Linux command to do this. Which I will go over in another Linux tutorial.

I have also seen a few Linux beginners having trouble moving files in Linux that have special characters in them. So to move files with special characters in Linux you will simple escape the characters that hold special meanings, like a space, (, or ). So for example I have a file named DSC06540 (New LCD TV).JPG this is an ugly filename but to move this file from my compact flash drive on my camera to my /home/max/images/electronics directory, I would simple escape all the special characters with a \ like this mv /media/CF/DSC06540\ \(New\ LCD\ TV\).JPG /home/max/images/electronics/

Another command I use quite often with the mv shell command is find. I can have find search for files on my computer and move the files to a new location. To do this there are 2 methods you can use, one method of using Linux find to move files is a small script, for example if I want to move all my php files to /home/max/htdocs/ I would run this: for i in `find *php`; do mv $i /home/max/htdocs; done.

Method 2 that uses Linux find command to move files in Linux is using the -exec option of find to execute mv. This command was brought to my attention a few days ago by another Linux user, and it is much faster than my method. Using the same example to move my php files, but using this method, you will run: find *php -exec mv {} /home/max/htdocs \; which is a lot less to type!

You can also change your find options any way you prefer to search your hard drive for the files you are looking for. Which I will go over in another Linux tutorial.

As you can see it isn’t hard at all to move files and folders in Linux shell prompt at all. As always I hope this Linux tutorial for beginners has helped you learn more about the Linux mv command. I hope you come back and find more help on Beginner Linux Tutorial.

Comment Linux tutorial or Leave a Trackback


  1. Posted July 1, 2010 at 3:41 am | Linux tutorial comment

    I am trying to move like this:
    mv /home/volkan/indirilenler/ /media/Yeni Birim/Film/

    /media/Yeni Birim/Film/ in there, there is space between “Yeni” and “Birim”. What should i put character for space?
    Error is mv: target `Birim/Film/’ is not directory

    Also i cant change “Yeni Birim” name becouse it is partitions i think.

  2. Posted August 15, 2010 at 1:01 pm | Linux tutorial comment

    When you are using the command line space is a special character. So to make CLI see it as an actual space, you need to escape it.
    mv /home/volkan/indirilenler/ /media/Yeni\ Birim/Film/
    use a \ (backslash) before the space anytime you need an actual space.

  3. apit
    Posted May 2, 2011 at 10:50 pm | Linux tutorial comment command…but i’ve make some mistake. I just move all my files(list of log file) to folder that never been created. This is the command looks like :

    [root@umpwins hafiz]# find Cfg* -exec mv {} /home/hafiz/Config/Aprl11/Log \;

    Folder “Log” is never been created before. So when i move to the path /home/hafiz/Config/Aprl11 and using command “ls -l” the output is as below :

    [root@umpwins Aprl11]# ls -l
    total 16
    -rw-r–r– 1 hafiz hafiz 12483 Apr 29 00:54 Log

    How to get back my original file?

  4. d
    Posted June 15, 2011 at 1:53 pm | Linux tutorial comment

    im trying to move all files in ascii format into new directory name=asc. what did I do wrong in the following?

    mv *.asc < /asc

  5. Posted June 16, 2011 at 1:20 am | Linux tutorial comment

    mv *.asc /path/to/asc/

One Trackback

  1. […] mv – the Linux terminal command to move files|directories. Like the cp command, but deletes the original source. […]

Post a Comment

Your email is never published nor shared. Required fields are marked *