Let's see how to create, remove and manipulate files directly from the terminal.
So in this lesson you will learn a few more commands that are quite important.
And don't worry if you start to think, well, that's a lot of comments because you can download a recap
PDF at the end of this section.
So at the end of section nine, download the PDF and you have all the commands that we run in this section.
And actually before we do anything here you can see that.
Well I have quite a lot of stuff here printed on the terminal.
So if I want to start, if I want to kind of clean the terminal, if I want to clear what's on the terminal,
I can use the command clear like that.
Okay.
If I run clear and I press enter, you see that my terminal is now empty.
So it's quite useful when you want to start from a clean state right now.
How to create a file?
I'm going to use a file manager on the side.
And what you have seen on the file manager is you right click new file and then you create a file with
a name etc. but you can do that from the terminal.
We have already seen that with nano.
If you use nano with a new file name is going to create the new file, but you can directly create a
file with the command touch.
And then let's say the name is ABC.
So touch and then space.
And then the file name you press enter and we have a new file.
If I do ls you see I have my new file ABC.
And this file is also on the file manager here okay.
Because this is the same.
Great.
And after you create a file you can also decide to remove the file.
So the command to remove the file is r m for remove.
And then just so space and the name of the file.
And you can use the autocompletion as well.
So I want to remove this file ABC.
If I do ls the file is not here anymore and also has disappeared from the file manager.
All right.
So that's how to create and to remove a file.
You do touch and RM.
Now if you want to create and remove a folder.
So to create a folder you don't use touch.
To create a folder you use mkdir which is basically make directory.
So you make a new directory, you put space and then you put the name for example new folder.
And note here it's quite important.
So for anything actually for any name, for any file name or any folder name, you will not put any
space in it.
If you want to put a space you can for example, use a underscore.
Let's see actually what's going to happen if I try to create.
So if I do mkdir and then new and then space folder.
So let's run that.
It's going to work.
But then let's see what we have.
What we have a new folder here.
And we have a folder folder here.
So by putting a space actually space means that you're going to create two folder names.
All right.
So for touch actually for any command touch rm mkdir.
If you want to apply this command to several files or folders, you just put the list of all the names
here separated by a space.
So here we instructed the command to create two new folders.
If I want to create my folder with so mkdir new underscore folder.
You can see now I have my new folder here that's correctly created.
And also we can see the same as always here.
You see we have the new the new folder and the folder.
Now if I want to remove a folder I will also use the r m command.
But let's see if I want to remove for example the new.
Then we get an error okay.
You cannot just use rm with a directory.
You need to use r m dash r for recursive.
So it's going to remove the folder and also everything that's inside.
So you put R and then dash r that's an option.
And then the name.
So you can put this name.
And also you can put a space and any other name.
So for example I can even remove folder and then space new.
To remove those two folders here I press enter and that's going to work.
You see those two folders are gone.
And let's also remove.
So r m r new folder.
And you can see I can use the autocompletion as well.
So here actually I use the autocompletion I have the f, I press tab again.
So twice more actually.
And I have new file and new folder okay.
So from that point I need to provide more information because the terminal cannot choose for me.
So I will put the O and then tab again.
So I want to remove the new folder.
Great.
So you have seen how to create a file with touch, how to remove it with RM, and then how to create
a folder with mkdir and how to remove with rpm and then dash r.
Now let's clear that and let's see how to move a file, because maybe you want to move a file.
Let's say that I have my new file here.
So this new file contains the text we have written in the previous lesson.
We want to move that inside the document.
So here you would just drag it and drop.
But we can do that from the terminal with the command m v so mv for move.
So I will do mv.
And then the first argument is going to be the file that I want to move.
So here the file is a new file.
So note that here I just write new file because I'm in my home directory, so I have direct access to
this.
So this is the relative path.
Now if I want to put that inside the documents I can do doc.
So I press tab here and I move that inside documents.
And I can also provide the absolute path slash home slash pi slash documents or even tilde slash documents.
That's going to be the same.
So MV and then I put the file name and then the basically the folder where I want to move the file.
And you see now the new file is gone.
If I do CD documents ls the file is here.
And so I can do mv new file and I can do dot dot to move it back to the previous folder.
Okay.
And then I do CD dot dot to go back to the previous folder.
And the new file is back again here.
All right.
You can use also move to just actually rename a file.
So you can rename and move the file at the same time.
For example I can do move new file And then test file.
For example, if I do this, I do ls.
You will see that my.
So the new file is gone and instead we have test file.
It just has been renamed.
And you can combine the two.
You can do.
So now I have a test file.
If I provide the path to documents and then ABC I'm just going to rename test file as ABC.
Inside the documents folder I go to documents with CD documents.
And you see now we have ABC and then I can move it back let's say so ABC, I move it back.
So dot dot slash new file okay.
So that's the directory dot dot slash.
And then the name for the file I go back ls the new file is back here again.
All right.
So the move command is quite useful.
You can move a file.
You can rename a file and you can do both at the same time.
Now what if you don't want to move a file.
But what if you want to make a copy of a file.
So let's clear here.
Let's do LZ.
We want to make a copy of that file.
First, let's see what's inside this file with Cat.
So we have already seen this comment but I just put it again here.
So cat new file with Autocompletion.
You see this is the text we have in this file.
Now if I want to make a copy of that file I can use the command c p for copy.
And then well I will first need to put what file I want to copy.
So that's going to be new file.
And I can also use the autocompletion.
And then I will need to put while the file name that I want to copy this file into.
So that's going to be a new name.
For example I will put new file two.
So it must be a different name.
I press enter.
And now if I do ls you see that I have my new file.
It's still the same.
So the CP command is not going to modify anything in this file.
But it's going to create another one with the name that you choose.
And that contains the same thing as the first one.
We can verify that with cat new.
So I press tab new file.
And then I need to put But two I press enter and you see that while the this file contains the same
content as that one.
All right.
So that's pretty much it for creating, removing and manipulating files from the terminal.
And with all those commands.
Well don't worry once again because you don't need to learn anything by heart.
You just need to practice.
The most important is actually to understand how the commands are working.
Then you need some practice, and after some practice you will just remember the comments because,
well, you will have written the command many times and in the meantime you can just download the PDF
at the end of this section.
And with this PDF you have all the commands in just two pages, so you can easily find what commands
you need to use for what situation.
And basically, with all the commands you've seen so far in this course, well, you will be able to
do between maybe 60 to 80% of what you need to do in the terminal.
Okay.
So even if there are hundreds and thousands of possible commands to use, in the end you will just use
a few many times.
And those few are very important to master.
And those are actually the ones that we saw in this course.