Here is the video version, if you prefer it:
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:
and say I want to copy the file
/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 ..
anaconda3 hadoop-example snap
'Calibre Library' Music stanfordnlp_resources
Desktop part-r-00000 Templates
Documents Pictures Untitled.ipynb
Downloads Public Videos
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
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 http://linuxcommand.org/tlcl.php. Pages 52-54
Subscribe to my newsletter to keep abreast of the interesting things I'm doing. I will send you the newsletter only when there is something interesting. This means 0% spam, 100% interesting content.