Pin Me

Moving And Copying Files In Linux

written by: •edited by: Michael Dougherty•updated: 5/23/2011

Most Linux distributions come with a graphic file manager, but if you need to move or copy files using the command line this article tells you how.

  • slide 1 of 4

    Graphic file managers

    Graphic file managers:

    Most Linux distributions now come with a GUI and a graphic file management system. On GNOME based distributions this will usually be Nautilus and KDE systems Konqueror. Both work in a similar way to the Windows File Manager in that files can be moved by dragging them between windows or between different folders in the same window and copied by doing the same thing with the Control key held down. Both file managers come with an Edit menu which contains Copy, Cut and Paste options that can also be used to move or copy files.

    Command-line move or copy:

    The terminal window can also be used to copy and move files. But for this user you will need to know a little about the Linux file structure. The Linux file system stems from a single root directory represented by a slash character (Windows uses a backslash). Immediately under this there are usually between fifteen and twenty system directories with names like bin, dev and etc. We are mainly concerned with two of these called media and home respectively. The media folder is our gateway to any external devices like CD-ROM's or USB memory sticks and the home folder is where each user’s individual documents and settings are stored. So if Tom, Sue and I all have accounts on the same PC, there will be folders under the home folder called ‘Tom’, ‘Sue’ and ‘Jon’.

  • slide 2 of 4

    Command-line operations

    A command line terminal window should be accessible from one of the menus. In Ubuntu for instance it is found by default under Applications / Accessories. This will open up a text entry window with a prompt and flashing cursor. The prompt includes a path string that tells the user whereabouts on the system he or she is located, for instance.

    root@jon-ubuntu-laptop:/# – I am located in the root directory

    root@jon-ubuntu-laptop:/media# – I am located in the media directory

    A tilde character (~) is used to indicate the user’s own subdirectory: e.g.

    root@jon-ubuntu-laptop:~# – I am located in my subdirectory under /home i.e. /home/jon

    The ‘cd’ (change directory) command is used to move through the system. To move one level upward towards the root directory I enter the command.

    cd ..

    To move downwards into a subdirectory I enter ‘cd’ followed by the directory name e.g. if I am in the home directory then ‘cd jon’ will take me down from /home into /home/jon. The ‘cd ~’ (tilde) command will always take me to my home directory and ‘cd /’ will take me straight to the root directory.

    cd jon - down to jon

    cd .. - up one level

    cd / - up to root directory

    cd ~ - to home directory

  • slide 3 of 4

    Using path commands

    Keep in mind that Linux is case sensitive – ‘cd’ is not the same as ‘CD’ and ‘newstuff’ is not the same as ‘Newstuff’, you need to be careful with your use of upper and lower case.

    Suppose that I am in the /home/jon/newstuff directory and there is a file there called ‘gettingolder.doc’ which I want to move to the /home/jon/oldstuff directory. The basic command for moving a file is ‘mv’, followed by the name of the file and followed by the destination directory. So the command I need here would be:

    mv gettingolder.doc ../oldstuff

    In other words pick up the file from this directory. Go up one level and down again into the oldstuff directory and drop it there.

    An alternative would be

    mv gettingolder.doc /home/jon/oldstuff

    where the complete path name to reach the destination directory is supplied.

    For a command that will work from anywhere on the file system I can supply a path name for both the source and the destination:

    mv /home/jon/newstuff/gettingolder.doc /home/jon/oldstuff

    For a command that will move several files I can use the asterisk character as a wild card to stand in for any set of characters: e.g.

    mv /home/jon/newstuff/*.doc /home/jon/oldstuff

    will move any files with a .doc extension in the newstuff directory to the oldstuff directory.


    mv /home/jon/newstuff/*.* /home/jon/oldstuff

    will move all the files in newstuff to oldstuff.

    What about copying? Just replace the mv command with cp and the files will be copied rather than moved.

  • slide 4 of 4

    External media

    The root directory of an external volume such as a CD-ROM or memory stick can be found as a directory under the /media directory. For instance, to copy the .HTM files from a directory on a CD-ROM to the newstuff directory the command might be:

    cp /media/cdrom/tutorial/*.htm newstuff

    and to move all files from the home/jon/oldstuff directory to a memory stick it would be something like:

    mv /home/jon/oldstuff/*.* /media/disk

    Finally for help on any terminal commands such as cp, cd or mv, just type 'man' in the terminal window followed by the command:

    man cp

    man cd

    man mv

    That's all you need to know!