WEBVTT

00:00.080 --> 00:05.090
Let's see how to create, remove and manipulate files directly from the terminal.

00:05.090 --> 00:09.680
So in this lesson you will learn a few more commands that are quite important.

00:09.680 --> 00:15.080
And don't worry if you start to think, well, that's a lot of comments because you can download a recap

00:15.080 --> 00:17.450
PDF at the end of this section.

00:17.450 --> 00:23.000
So at the end of section nine, download the PDF and you have all the commands that we run in this section.

00:23.000 --> 00:25.670
And actually before we do anything here you can see that.

00:25.700 --> 00:28.580
Well I have quite a lot of stuff here printed on the terminal.

00:28.580 --> 00:35.210
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,

00:35.210 --> 00:38.090
I can use the command clear like that.

00:38.120 --> 00:38.480
Okay.

00:38.510 --> 00:43.640
If I run clear and I press enter, you see that my terminal is now empty.

00:43.670 --> 00:48.050
So it's quite useful when you want to start from a clean state right now.

00:48.050 --> 00:50.000
How to create a file?

00:50.000 --> 00:51.740
I'm going to use a file manager on the side.

00:51.740 --> 00:56.990
And what you have seen on the file manager is you right click new file and then you create a file with

00:56.990 --> 01:00.140
a name etc. but you can do that from the terminal.

01:00.140 --> 01:02.270
We have already seen that with nano.

01:02.300 --> 01:08.090
If you use nano with a new file name is going to create the new file, but you can directly create a

01:08.090 --> 01:09.740
file with the command touch.

01:09.740 --> 01:12.530
And then let's say the name is ABC.

01:12.530 --> 01:14.060
So touch and then space.

01:14.060 --> 01:18.170
And then the file name you press enter and we have a new file.

01:18.170 --> 01:21.380
If I do ls you see I have my new file ABC.

01:21.740 --> 01:26.870
And this file is also on the file manager here okay.

01:26.900 --> 01:27.980
Because this is the same.

01:27.980 --> 01:28.730
Great.

01:28.730 --> 01:32.630
And after you create a file you can also decide to remove the file.

01:32.630 --> 01:36.440
So the command to remove the file is r m for remove.

01:36.440 --> 01:39.470
And then just so space and the name of the file.

01:39.470 --> 01:41.360
And you can use the autocompletion as well.

01:41.360 --> 01:43.850
So I want to remove this file ABC.

01:43.880 --> 01:49.880
If I do ls the file is not here anymore and also has disappeared from the file manager.

01:50.450 --> 01:50.720
All right.

01:50.720 --> 01:53.810
So that's how to create and to remove a file.

01:53.810 --> 01:55.760
You do touch and RM.

01:55.790 --> 01:58.940
Now if you want to create and remove a folder.

01:58.940 --> 02:01.340
So to create a folder you don't use touch.

02:01.340 --> 02:08.030
To create a folder you use mkdir which is basically make directory.

02:08.030 --> 02:14.680
So you make a new directory, you put space and then you put the name for example new folder.

02:14.680 --> 02:16.270
And note here it's quite important.

02:16.270 --> 02:22.240
So for anything actually for any name, for any file name or any folder name, you will not put any

02:22.240 --> 02:23.350
space in it.

02:23.350 --> 02:26.950
If you want to put a space you can for example, use a underscore.

02:26.980 --> 02:30.700
Let's see actually what's going to happen if I try to create.

02:30.730 --> 02:35.140
So if I do mkdir and then new and then space folder.

02:35.590 --> 02:36.940
So let's run that.

02:36.940 --> 02:38.050
It's going to work.

02:38.050 --> 02:40.120
But then let's see what we have.

02:40.120 --> 02:42.700
What we have a new folder here.

02:42.700 --> 02:45.610
And we have a folder folder here.

02:45.610 --> 02:50.860
So by putting a space actually space means that you're going to create two folder names.

02:51.070 --> 02:51.310
All right.

02:51.340 --> 02:55.660
So for touch actually for any command touch rm mkdir.

02:55.690 --> 03:02.020
If you want to apply this command to several files or folders, you just put the list of all the names

03:02.020 --> 03:03.460
here separated by a space.

03:03.460 --> 03:07.780
So here we instructed the command to create two new folders.

03:07.780 --> 03:13.150
If I want to create my folder with so mkdir new underscore folder.

03:13.540 --> 03:18.100
You can see now I have my new folder here that's correctly created.

03:18.100 --> 03:21.370
And also we can see the same as always here.

03:21.370 --> 03:25.180
You see we have the new the new folder and the folder.

03:25.180 --> 03:29.620
Now if I want to remove a folder I will also use the r m command.

03:29.620 --> 03:33.100
But let's see if I want to remove for example the new.

03:33.130 --> 03:35.440
Then we get an error okay.

03:35.470 --> 03:38.320
You cannot just use rm with a directory.

03:38.320 --> 03:42.070
You need to use r m dash r for recursive.

03:42.070 --> 03:45.580
So it's going to remove the folder and also everything that's inside.

03:45.580 --> 03:48.730
So you put R and then dash r that's an option.

03:48.730 --> 03:50.050
And then the name.

03:50.050 --> 03:51.220
So you can put this name.

03:51.220 --> 03:54.400
And also you can put a space and any other name.

03:54.400 --> 03:57.880
So for example I can even remove folder and then space new.

03:57.880 --> 04:03.610
To remove those two folders here I press enter and that's going to work.

04:03.640 --> 04:05.800
You see those two folders are gone.

04:05.800 --> 04:07.210
And let's also remove.

04:07.210 --> 04:11.230
So r m r new folder.

04:11.230 --> 04:13.990
And you can see I can use the autocompletion as well.

04:14.140 --> 04:18.200
So here actually I use the autocompletion I have the f, I press tab again.

04:18.200 --> 04:20.000
So twice more actually.

04:20.000 --> 04:22.430
And I have new file and new folder okay.

04:22.460 --> 04:27.200
So from that point I need to provide more information because the terminal cannot choose for me.

04:27.200 --> 04:30.620
So I will put the O and then tab again.

04:30.740 --> 04:32.780
So I want to remove the new folder.

04:32.810 --> 04:33.230
Great.

04:33.230 --> 04:38.960
So you have seen how to create a file with touch, how to remove it with RM, and then how to create

04:38.960 --> 04:44.510
a folder with mkdir and how to remove with rpm and then dash r.

04:44.540 --> 04:51.410
Now let's clear that and let's see how to move a file, because maybe you want to move a file.

04:51.410 --> 04:53.870
Let's say that I have my new file here.

04:53.870 --> 04:59.570
So this new file contains the text we have written in the previous lesson.

04:59.570 --> 05:02.240
We want to move that inside the document.

05:02.240 --> 05:04.610
So here you would just drag it and drop.

05:04.640 --> 05:10.640
But we can do that from the terminal with the command m v so mv for move.

05:10.640 --> 05:12.020
So I will do mv.

05:12.020 --> 05:15.290
And then the first argument is going to be the file that I want to move.

05:15.290 --> 05:18.380
So here the file is a new file.

05:18.380 --> 05:23.820
So note that here I just write new file because I'm in my home directory, so I have direct access to

05:23.850 --> 05:24.030
this.

05:24.030 --> 05:26.400
So this is the relative path.

05:26.430 --> 05:32.340
Now if I want to put that inside the documents I can do doc.

05:32.340 --> 05:35.700
So I press tab here and I move that inside documents.

05:36.000 --> 05:44.460
And I can also provide the absolute path slash home slash pi slash documents or even tilde slash documents.

05:44.460 --> 05:45.420
That's going to be the same.

05:45.420 --> 05:51.090
So MV and then I put the file name and then the basically the folder where I want to move the file.

05:51.090 --> 05:53.850
And you see now the new file is gone.

05:53.850 --> 05:58.200
If I do CD documents ls the file is here.

05:58.230 --> 06:06.720
And so I can do mv new file and I can do dot dot to move it back to the previous folder.

06:06.750 --> 06:07.080
Okay.

06:07.110 --> 06:10.800
And then I do CD dot dot to go back to the previous folder.

06:10.800 --> 06:13.980
And the new file is back again here.

06:14.010 --> 06:14.670
All right.

06:14.670 --> 06:18.870
You can use also move to just actually rename a file.

06:18.900 --> 06:21.150
So you can rename and move the file at the same time.

06:21.150 --> 06:27.270
For example I can do move new file And then test file.

06:27.270 --> 06:30.930
For example, if I do this, I do ls.

06:30.960 --> 06:32.250
You will see that my.

06:32.280 --> 06:35.550
So the new file is gone and instead we have test file.

06:35.550 --> 06:37.080
It just has been renamed.

06:37.080 --> 06:38.250
And you can combine the two.

06:38.280 --> 06:38.850
You can do.

06:38.850 --> 06:40.980
So now I have a test file.

06:40.980 --> 06:47.820
If I provide the path to documents and then ABC I'm just going to rename test file as ABC.

06:47.820 --> 06:53.610
Inside the documents folder I go to documents with CD documents.

06:53.610 --> 06:59.460
And you see now we have ABC and then I can move it back let's say so ABC, I move it back.

06:59.460 --> 07:03.360
So dot dot slash new file okay.

07:03.390 --> 07:06.780
So that's the directory dot dot slash.

07:06.810 --> 07:14.880
And then the name for the file I go back ls the new file is back here again.

07:14.910 --> 07:15.360
All right.

07:15.360 --> 07:17.730
So the move command is quite useful.

07:17.730 --> 07:18.960
You can move a file.

07:18.960 --> 07:22.020
You can rename a file and you can do both at the same time.

07:22.020 --> 07:23.970
Now what if you don't want to move a file.

07:23.970 --> 07:27.120
But what if you want to make a copy of a file.

07:27.150 --> 07:28.530
So let's clear here.

07:28.560 --> 07:29.760
Let's do LZ.

07:29.790 --> 07:32.490
We want to make a copy of that file.

07:32.520 --> 07:35.490
First, let's see what's inside this file with Cat.

07:35.490 --> 07:38.910
So we have already seen this comment but I just put it again here.

07:38.910 --> 07:41.820
So cat new file with Autocompletion.

07:41.820 --> 07:44.670
You see this is the text we have in this file.

07:44.700 --> 07:50.640
Now if I want to make a copy of that file I can use the command c p for copy.

07:50.640 --> 07:54.420
And then well I will first need to put what file I want to copy.

07:54.420 --> 07:56.100
So that's going to be new file.

07:56.100 --> 07:57.930
And I can also use the autocompletion.

07:57.930 --> 08:02.850
And then I will need to put while the file name that I want to copy this file into.

08:02.880 --> 08:04.290
So that's going to be a new name.

08:04.500 --> 08:07.440
For example I will put new file two.

08:07.470 --> 08:09.150
So it must be a different name.

08:09.150 --> 08:10.470
I press enter.

08:10.470 --> 08:13.860
And now if I do ls you see that I have my new file.

08:13.860 --> 08:14.520
It's still the same.

08:14.520 --> 08:18.480
So the CP command is not going to modify anything in this file.

08:18.480 --> 08:21.930
But it's going to create another one with the name that you choose.

08:21.930 --> 08:24.960
And that contains the same thing as the first one.

08:24.960 --> 08:28.230
We can verify that with cat new.

08:28.230 --> 08:30.750
So I press tab new file.

08:30.750 --> 08:37.010
And then I need to put But two I press enter and you see that while the this file contains the same

08:37.010 --> 08:38.480
content as that one.

08:38.510 --> 08:38.930
All right.

08:38.930 --> 08:44.510
So that's pretty much it for creating, removing and manipulating files from the terminal.

08:44.510 --> 08:45.650
And with all those commands.

08:45.650 --> 08:49.880
Well don't worry once again because you don't need to learn anything by heart.

08:49.910 --> 08:51.500
You just need to practice.

08:51.500 --> 08:55.670
The most important is actually to understand how the commands are working.

08:55.670 --> 09:00.020
Then you need some practice, and after some practice you will just remember the comments because,

09:00.050 --> 09:05.870
well, you will have written the command many times and in the meantime you can just download the PDF

09:05.900 --> 09:07.010
at the end of this section.

09:07.010 --> 09:11.600
And with this PDF you have all the commands in just two pages, so you can easily find what commands

09:11.600 --> 09:13.400
you need to use for what situation.

09:13.400 --> 09:17.780
And basically, with all the commands you've seen so far in this course, well, you will be able to

09:17.780 --> 09:22.790
do between maybe 60 to 80% of what you need to do in the terminal.

09:22.820 --> 09:23.060
Okay.

09:23.090 --> 09:29.900
So even if there are hundreds and thousands of possible commands to use, in the end you will just use

09:29.900 --> 09:31.670
a few many times.

09:31.670 --> 09:33.680
And those few are very important to master.

09:33.680 --> 09:37.100
And those are actually the ones that we saw in this course.
