Hello the beautiful people.
And welcome to this video where you're going to learn how to copy and paste files and folders using
the command line.
Now, this should be a nice and quick lecture with just one command, the CP command, which handles
all the copying of files and folders in Linux, and by the end of the video you'll know how to copy
and paste files and folders using the command line, and you'll also see how to use the CP command with
wildcards to make copying and pasting even more awesome.
So let's go ahead and get right into it.
Okay.
So here we are.
And as you can see by the Shell prompt, I'm currently on the desktop and on the desktop I have a file
here called file one point txt and if I open that it says hello there you beautiful people.
I wonder how that got there.
So let's say we wanted to copy that file to another file called file two dot txt because I'm very,
very imaginative.
So to copy it we need to use the c p command and the CP being short for copy.
Now we just need to tell the copy command what we want to copy and where we want to copy it to.
So what do we want to copy.
Well we want to copy file one dot txt and remember I'm on the desktop already in the shell so I can
just write file one at txt.
If I was in the home folder I would say copy desktop such file one txt just just so that you're aware.
So let's go to the desktop again.
So we need to tell it what we want to copy and where we want to copy it to.
So we want to copy far one txt and we want to copy it to another file called file to txt.
So that's all we've got to type one to copy file one into another file called file to txt.
And when I do that, we'll see we get a file here called file two.
And when I open that that also says hello there, you beautiful people.
Okay.
So that's how you copy a file to another file, which is pretty simple.
So how would you copy a file to another folder to one of the directory?
Well, that's pretty simple too.
As, as I say, the copy command, all you've got to do is tell it what you want to copy and where you
want to copy it to.
Okay.
So let's say I want to copy file one into this folder called Destination.
So all I have to do is say copy file one so far one txt and copy it to destination.
And also let's say I also wanted to copy file two at the same time.
So want to copy file one and file two into the destination folder.
So you can see here that the last thing that you put as a command line argument is the destination and
everything else that comes before that is what you want to copy.
So I could have many, many, many different commands and many, many different files that I want to
copy here.
But the last one is where I want to copy them all to.
Okay, so with that, let's go ahead and press enter.
And when I look inside destination, we can see that we've got far one and file two.
They have both been copied into there.
So as you can see, this whole copying and pasting business is actually rather simple with the command
line.
And of course you can also do it with wildcards.
So I'm on the desktop at the minute.
Let's say I want to remove everything that starts with the word file.
So if I do that, both the text files should disappear because they both begin with the word file.
So if I do that, they are.
They've both disappeared.
Now I can copy and paste all the stuff from in the destination folder to the desktop by just saying
copy destination, slash everything to this folder.
Now how do I select this folder?
Well, if you remember back the there's always a hidden folder in each location that refers to the folder
that it is.
So if I just do and that is the full stop.
So if I just do that, that dot, what that means is copy everything from within the destination folder
into this folder which is the desktop, which is where we currently are.
So if I do that, if I press enter, you'll see that file one and file two have been copied and pasted
to this location, which is represented by the full stop here.
And if you don't remember, if I just do ls with the a option.
You can see here that we've got these two hidden folders and the one with the one dot refers to this
folder and the one with the double dot refers to the folder above it, which is our home folder.
Okay.
So I could for example, copy everything from the destination folder to the parent folder of where we
currently are, which is the home folder.
So if I do that and I now look in our home folder, we can see that file one and file two have been
created in there.
So look, wildcards work absolutely great with any command, even the copy command as well.
So let's clear the screen.
We have seen how to copy and paste a file into another file.
We've seen how to copy and paste a file into a folder and we've seen how to copy and paste files from
folders into other folders.
The only other thing we need to know is how to copy and paste entire folders.
So we have here this copy me folder on the desktop and that's got three files in it.
It's got file, file B and file, see.
Okay.
And we want to copy this entire folder into the destination folder.
So we don't just want the files, we want the folder as well.
So we don't just want the chocolate, we also want the wrapper.
Okay.
So the way that we can do this is by giving the C p command the R option, which also stands for recursive.
Now, if you remember from when we were deleting files and folders in the last few videos with the option
recursive deleting meant delete that folder and everything inside it and it's very similar for the copy
command.
What we're saying is copy the folder and everything inside of it.
So to actually copy the copy MI folder into the destination folder, we just type it out.
We say, we say copy with the R option, then copy me into the destination folder.
And if I do that and then we look inside destination, we will see that the copy me folder has been
copied and pasted and all of the different files are inside there as well.
All safe and sound.
So there you have it.
You can now copy and paste files and folders using the command line.
It's quite easy, right?
So as a very quick review, you saw that the CP command is what deals with copying and pasting of files
and folders in Linux.
And the way that it works is you have the CPP, you type CPP, then what you want to copy and you can
have as many of those as you like.
And then at the end, the last command line argument that you give it is your destination.
So you can have many things that you want to copy.
But the final thing that you give it is the single destination where you want all of those things to
go.
Now, if you want to copy entire folders, so not just their contents, but the actual wrapper, the
actual folder itself, then you need to give the copy command the are option to allow it to copy entire
folders recursively and now with copying and pasting on the way.
Up next, what we're going to be doing is we're going to be discussing moving and renaming files and
directories in Linux.
And what's really interesting is that you can actually use just one command to do both of those things.
So to learn how to move and rename files using just one command.
I'll see you in the next video.