Learn to copy files and directories at the Linux command line.
Linux cp command summary with examples (4:06)
Videos can also be accessed from the YouTube Playlist.
Our twenty-third word, or command to memorize is
cp from the category
cp allows you to copy files or
Recall from the last video (tutorial) we created directories to hold our stuff, now we'll copy files and directories to hold that stuff.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s).
cp command has
31 options and two arguments, the first is the
source and the second is the
Like most commands, help is available with double-dash
-i, or interactive mode will
prompt you before overwriting files, as the dangerous default with
cp is to overwrite silently.
-rrecursive option is required to copy directory contents, and then
-uonly copies the source when it is newer, like a backup would.
So why is
cp an important command?
cp is used for routine copies,
backups and setting up file structures.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go, let's do a quick
then make a copy,
cp -i of
video20.txt, which is the
source, and call it
destination. In the same directory.
Oh wow, look at that, good thing we used the
-i, I forgot, I edited video23.txt
already. Now try
cat to verify.
And that is the case. Look at that. So
-i helped us in that case
otherwise it would have overwritten.
Next, copy that file into the one of the two subdirectories within
stuff, from the last video (tutorial),
morestuff and verify.
And then last, let's copy that
morestuff directory with the file,
-r option, into another one
yourstuff, and then
ls again to verify.
Okay now you know how to use
And you know the syntax for commands, options and arguments.
One last tip about the
Check out the
-a option. Copying
directories requires it, or
-a retains all of the
Okay, thanks for visiting today. I hope this was a helpful
introduction to the
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
We'd love to have you join our growing YouTube Channel.
mkdircommand, hit Back.
mvcommand, click Next.