Linux Tutorial Series

Linux Tutorial Series – 34 – The cp command

Here is the video version, if you prefer it:

The cp command copies files or directories. (Shotts, 2019)⁠ It can be used to copy only one file or directory to a destination or multiple files or directories to a destination. I remember the syntax most easily by remembering the following:

cp source destination

So first you specify what you want to copy, then where you are copying it to. For multiple files, I remember it by:

cp source1 source2 … destination

Let’s say I have the following situation:

mislav@mislavovo-racunalo:~/grep-hadoop-example$ ls

part-r-00000 _SUCCESS

and say I want to copy the file part-r-00000 to /home/mislav directory. I would do that by writing:

mislav@mislavovo-racunalo:~/grep-hadoop-example$ cp part-r-00000 /home/mislav

Now when I position myself in my /home/mislav folder, I see the file I just copied:

mislav@mislavovo-racunalo:~/grep-hadoop-example$ cd ..

mislav@mislavovo-racunalo:~$ ls

anaconda3 hadoop-example snap

'Calibre Library' Music stanfordnlp_resources

Desktop part-r-00000 Templates

Documents Pictures Untitled.ipynb

Downloads Public Videos

grep-hadoop-example Python-3.7.4

Great! Two more useful things:

You can run cp with the -i option, which asks you if you want to override a file. If I were to copy another file named part-r-00000 to /home/mislav, cp would silently overwrite the existing file. You would never know! However, if you run it with the -i option, it doesn’t silently overwrite files.

Another useful option is the -u option, which only copies the files that either don’t exist or are newer at the source than at the destination.

Alright, I am leaving you here. Hope you learned something useful.


Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from Pages 52-54