Advertisement
Tech

How To Move And Copy Files Under Linux

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.

By Finn Orfano
Desk Tech
Reading time 4 min read
Word count 810
Linux Computing Linux desktops
How To Move And Copy Files Under Linux
Advertisement
Quick Take

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.

On this page

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.

Advertisement

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’.

Advertisement

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

Advertisement

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.

Advertisement

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.

Advertisement

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.

Advertisement

cd jon - down to jon

cd .. - up one level

Advertisement

cd / - up to root directory

cd ~ - to home directory

Advertisement

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:

Advertisement

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.

Advertisement

An alternative would be

mv gettingolder.doc /home/jon/oldstuff

Advertisement

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:

Advertisement

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.

Advertisement

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

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

Also

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.

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!

Keep Exploring

More from Tech

Filed under
Linux Computing
More topics
Linux desktops
Advertisement