Instructor: Hey folks, in this video we are going to
learn how we could copy directories.
So we learned how to create files
and directories and we learned how to copy files.
Now let's focus on how you could copy the directories.
And the reason we wanted to do that is because
if we have some configuration files in a directory,
it's better that you make a copy
before you go in and modify it.
So to do the copy of a directory,
you use the same command cp, yes,
to copy a directory on Linux,
you have to execute the CP command
with the minus R option for recursive and specify the source
and destination directories to be copied.
For example,
CP minus R, the source folder
that you're copying, and the destination where
you're copying it to minus R needs to be used
because if you don't use it, it will complain.
It will say, Hey
I cannot copy this because this is a directory.
Alright, so let's go right into our Linux machine
and we will run a couple of commands.
So we could go through copying a directory.
So first things first, who am I?
I'm logged in as myself, which directory I'm in?
I'm in my home directory.
What's in my home directory?
These are the files and directories that I have.
Now for this practice, I'm going to create a new directory.
I'm gonna, I'm going to call it config because as I said,
most of the time you need to copy the entire directory.
If it has configuration files in case you make a mistake
then you could restore that configuration files
from a directory.
Alright, so configuration file directory has been created.
Now let's go inside of this config file,
and let's create configuration file.
So let's say I wanted to create a touch a.com file
b.com file and c.com file.
All right, so let's confirm.
Okay, so it has three directories created.
Now again, which directory I'm in, I'm in home
I have saw config directory.
So now let's go back to my home directory.
I could just type CD and hit enter and it will bring me back
to my home directory.
Now let's see, we have the config file.
Perfect. Now we need to copy this config file directory.
So we will do CP.
Now if we don't specify the minus R option,
let's see what happens.
Config directory, where we trying to copy it to?
To temp directory.
Now if you leave just temp like that, then it
will take the same name of config and we copied it over
copied it over, sorry.
But if you wanted to change the name
of the destination direction, you can by putting slash
config dash backup.
So just put back, now, hit enter, and you're gonna see
that it's gonna complain.
Copy omitting, directory config, because it thinks
that you're trying to copy a file.
So we have to let it
know that I'm not trying to copy a file,
I'm trying to copy a directory.
So let's do minus R.
Now we're doing config slash tab
and the name of the new name of the directory.
Alright, hit enter.
Beautiful. I got, we got our prompt back.
It means it worked.
How do we verify it?
We could just go into CD slash temp directory.
Do ls minus ltr
and you'll see at the bottom there is right here
it's a config directory that it copied.
Now let's go inside of this config
directory and do ls minus ltr
and you'll see all those three files that we created inside
of that directory has been copied as well.
So recursive also indicates the command that you
are copying a directory
plus it's telling it copy the sub folder in that directory
and the sub files or the files within that sub folders.