Hey, folks, in this video, we are going to learn how we could copy directories.
So we learn how to create files and directories and we'll learn 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.
P 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, CPP 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.
All right, 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 and 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.
All right.
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 touch a file, beacon file and see file.
All right, so let's confirm.
Okay.
So it has three directories created now in which directory.
Amen.
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 that config file.
Perfect.
Now we need to copy this config file directory so we will do CPP.
Now if we don't specify the minus R option, let's see what happens.
Config directory where we try 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 be copied over.
Copied over.
Sorry, but if you wanted to change the name of the destination directory, you can by putting slash
config dash backup.
So just put back now hit enter and you're going to see that it's going to 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 temp and the name of the new name of the directory.
All right, hit enter.
Beautiful.
Got we got our prompt back.
It means it worked.
How do we verify it?
We can just go into CD slash temp directory to ls minus l t r and you'll see at the bottom there is
right here.
It's a configure directory that it copied.
Now let's go inside of this config.
Directory and do ls minus l tr and you will see all those three files that we created inside of that
directory has been copied as well.
So a recursive also indicates the command that you are copying a directory plus it's telling it copy
the subfolder in that directory and the sub files or the files within that subfolders.