Hey and welcome back to
this video.
So let's continue. So we have
seen how to copy a file from one source to another
destination. Let's quickly see some more
ways to copy files and directories. Alright,
so let's quickly create two directories called
as one and two so we have to
directories now. So let's quickly create two files
as well. So for that we are going to use the command which
is
Nano
let's call it as file 1 and hit
enter and let's say this is file one.
And let's quickly save it come out of it Nano File
2.
This is file to save it.
And we have to folders or directories one
and two and two files which is file one
and file to perfect. So now
if I want to copy this file, which is a file
one. So I'm going to type the command CP file one
and copy it to the directory,
which is one.
And this should have copied the file
into the directory, which is 1 you can
also verify using the command tree so tree one
and it entered and you can see the tree
structure.
Of the directory, which is 1 and
there is a file which is a file one inside this
directory. Perfect.
And you can see the output over here as well 0 directories
and one file inside one folder.
Okay. So now let's
say I want to copy this directory. So
let's say copy the directory two.
So before copying the directory, let's copy the
file to as well into the directory, which
is two and hit enter and let's type
the command tree two and see if there
is a file and yes, there is a file. So let me type
the command tree over here and you can see there is
a directory one, which has a file one. There is
a directory two, which has a file too and here we
have to files as well, which is file one and file
too. Great. Let me clear the screen for you.
now
Let's say I want to copy the directory which is 2 inside
the directory 1. So this time I do not
want to copy a file instead. I want to
copy a directory for that. I'm going to use the command CP. So
let's say copy to to copy one and
hit enter and here you can see we got
an error. It says you're trying to copy
a directory and not specified hyphen
R. So omitting the directory now
here if you want to copy a
directory, you have to specify hyphen R
then and only then you will be
able to copy those directories. And now when
I hit enter let's go inside one
and see or else we can
also use the command tree.
And you can see inside the directory 1 we
have a directory which is 2 which contains a
file to and yes, we already copied a
file one inside the directory one, which is already present.
Let's go inside one and see as
well the same structure. There is a file one and
there is a new directory which has
been copied over here, which is two if we go
inside two and hit enter and see here
we can find the file which is file to which
is exactly the same structure that we see over here.
So I hope you guys understood how you
can copy directories recursively inside
another directories from one source to another
destination. This is very very handy, and people
many time make this mistakes while
copying directories, which you should always keep in
mind. I hope you guys understood. Thank you.