WEBVTT

00:00.850 --> 00:01.270
Hello.

00:01.270 --> 00:02.920
Welcome to another lecture of our course.

00:02.920 --> 00:09.610
In this lecture you will learn about how to handle, create, modify and delete files so the shell provides

00:09.610 --> 00:12.850
many file manipulation commands on the Linux file system.

00:12.850 --> 00:18.970
This lecture we will walk through the basic commands and the basic shell commands you need to handle

00:18.970 --> 00:19.510
files.

00:19.510 --> 00:20.740
So let's get started.

00:20.740 --> 00:21.490
My name is Stefan.

00:21.490 --> 00:23.470
Welcome to another lecture of our course.

00:34.960 --> 00:40.180
Every once in a while you run into a situation where you need to create an empty file.

00:40.210 --> 00:47.080
For example, sometimes applications accept a log file to be present before they can write to it.

00:47.110 --> 00:53.290
In these situations, you can use the touch command to easily create an empty file.

00:53.290 --> 00:59.020
In order to do that, for example, touch and my test file here.

00:59.020 --> 01:01.840
And as you can see here, we create a touch my test file.

01:01.840 --> 01:06.700
So the touch command creates the new file.

01:06.700 --> 01:12.310
You specify and assigns your username as the file owner like this.

01:12.310 --> 01:17.110
So as you can see, my username is the file owner and my machine is Kali here.

01:17.680 --> 01:26.980
So notice in this example that the file size is zero because the touch command just created an empty

01:27.010 --> 01:31.210
file so that touch command can also be used to change modification time.

01:31.210 --> 01:34.580
So this is done without changing the file contents.

01:34.580 --> 01:44.150
So we will do for example, and as you can see here, 313 and and as you can see, this is 313 now.

01:44.150 --> 01:51.740
So let's create again and my test file two and here LSL Clear.

01:52.070 --> 01:57.350
LSL And as you can see here, these have different times.

01:57.350 --> 02:00.350
They also created a time frames so.

02:04.620 --> 02:05.040
Yeah.

02:05.040 --> 02:12.870
And actually, if you if you want to update this file like this so you can also write test file, write

02:12.870 --> 02:15.030
the same name and.

02:16.230 --> 02:20.490
And as you can see here, we updated file time here.

02:20.490 --> 02:26.460
So creating empty files and altering file temp steps is not something you will do on a Linux system

02:26.460 --> 02:27.030
daily.

02:27.060 --> 02:32.420
However, copying files is an action you will do often while using Shell.

02:32.430 --> 02:35.070
So let's get started with copying files here.

02:35.070 --> 02:40.050
So copying files and directories from one location in the file system to another is a common practice

02:40.050 --> 02:41.850
for system administrators.

02:41.850 --> 02:44.760
So the CP command provides this feature.

02:44.760 --> 02:46.470
It is most basic form.

02:46.470 --> 02:52.160
The CP command uses two parameters, so two parameters.

02:52.170 --> 02:54.750
The first parameter is that CP.

02:56.230 --> 02:58.130
Is the source object.

02:58.130 --> 03:02.030
So in this case, we're going to firstly assign source.

03:02.630 --> 03:06.110
And after that, we will enter the destination.

03:06.930 --> 03:08.400
Destination.

03:13.080 --> 03:23.790
So here, when both source and destinations are parameters or file names, the CP command copies the

03:23.790 --> 03:27.060
source file to a new destination file.

03:27.820 --> 03:34.420
So the new file acts like a brand new file and with an updated modification time.

03:34.420 --> 03:37.230
So for example, let's do following here.

03:37.240 --> 03:40.380
LSL And here we have my test file.

03:40.390 --> 03:40.990
My test file.

03:41.170 --> 03:48.700
So let's copy my test file to the same location, but change the name to test here.

03:48.700 --> 03:50.710
Test file.

03:50.710 --> 03:53.490
Yeah, test file and let's do it.

03:53.500 --> 03:57.280
So we're going to do in order to do that, we're going to do my test file.

03:57.310 --> 03:59.950
Firstly, we're going to enter the source here.

03:59.950 --> 04:05.770
So my test file and after that we're going to enter the destination.

04:05.770 --> 04:08.380
And as you can see, the destination is going to be this.

04:08.380 --> 04:11.020
So destination is going to be test file.

04:11.740 --> 04:19.930
And here, oops, clear and L and here, as you can see here.

04:21.340 --> 04:22.930
We have a test file.

04:22.930 --> 04:27.730
The new with the new timestamp 315.

04:28.030 --> 04:33.790
But here, as you can see here, whenever we copied this, this also created a new timestamp.

04:33.790 --> 04:40.180
But the as you can see here, but the size and their contents should be the same.

04:40.180 --> 04:41.740
So the new.

04:43.210 --> 04:50.410
This file shows a different modification time than our previous test file.

04:50.410 --> 04:57.520
So if a destination file already exists, the CP command may not prompt you to this fact, so it is

04:57.520 --> 05:00.910
best to add the E option here.

05:00.910 --> 05:07.990
So e option to force the shell to ask whether you want to overwrite a file or not.

05:07.990 --> 05:10.930
So we will do that like this.

05:11.050 --> 05:18.640
RLS or cp here parameter as e here and overwrite test file.

05:18.640 --> 05:19.360
Yes.

05:19.360 --> 05:20.320
Or E here.

05:20.320 --> 05:24.310
And as you can see here L here you can also here.

05:24.340 --> 05:25.450
Let's see.

05:25.450 --> 05:32.860
And as you can see here, we override override on the test file and the timestamp and file contents

05:32.860 --> 05:36.550
should be updated with new file here.

05:36.550 --> 05:39.610
So if you don't answer the you here.

05:39.610 --> 05:45.740
So here, here, the file copy doesn't process and you can also enter the n here.

05:45.740 --> 05:47.150
So for no.

05:47.150 --> 05:56.360
So you can also copy a file into a pre-existing directory like this will be choosing the absolute directory.

05:56.480 --> 05:57.680
So cp.

05:58.710 --> 05:59.400
Or clear.

05:59.400 --> 06:02.090
Firstly, so cp e.

06:03.330 --> 06:05.220
Uh, for example, my test file.

06:05.220 --> 06:13.530
My test file, and we're going to do to my home, Carly And after that we will copy to, for example,

06:13.530 --> 06:15.840
templates or yeah, downloads.

06:16.320 --> 06:19.440
And here, let's see the two downloads.

06:19.800 --> 06:20.220
Oops.

06:20.280 --> 06:22.590
See the two downloads here.

06:22.590 --> 06:27.360
As you can see here we have a new file, my test file here.

06:27.510 --> 06:34.830
So the new file is now under the downloads directory using the same file name as the original.
