Hello.
Welcome to another lecture of our course.
In this lecture you will learn about how to handle, create, modify and delete files so the shell provides
many file manipulation commands on the Linux file system.
This lecture we will walk through the basic commands and the basic shell commands you need to handle
files.
So let's get started.
My name is Stefan.
Welcome to another lecture of our course.
Every once in a while you run into a situation where you need to create an empty file.
For example, sometimes applications accept a log file to be present before they can write to it.
In these situations, you can use the touch command to easily create an empty file.
In order to do that, for example, touch and my test file here.
And as you can see here, we create a touch my test file.
So the touch command creates the new file.
You specify and assigns your username as the file owner like this.
So as you can see, my username is the file owner and my machine is Kali here.
So notice in this example that the file size is zero because the touch command just created an empty
file so that touch command can also be used to change modification time.
So this is done without changing the file contents.
So we will do for example, and as you can see here, 313 and and as you can see, this is 313 now.
So let's create again and my test file two and here LSL Clear.
LSL And as you can see here, these have different times.
They also created a time frames so.
Yeah.
And actually, if you if you want to update this file like this so you can also write test file, write
the same name and.
And as you can see here, we updated file time here.
So creating empty files and altering file temp steps is not something you will do on a Linux system
daily.
However, copying files is an action you will do often while using Shell.
So let's get started with copying files here.
So copying files and directories from one location in the file system to another is a common practice
for system administrators.
So the CP command provides this feature.
It is most basic form.
The CP command uses two parameters, so two parameters.
The first parameter is that CP.
Is the source object.
So in this case, we're going to firstly assign source.
And after that, we will enter the destination.
Destination.
So here, when both source and destinations are parameters or file names, the CP command copies the
source file to a new destination file.
So the new file acts like a brand new file and with an updated modification time.
So for example, let's do following here.
LSL And here we have my test file.
My test file.
So let's copy my test file to the same location, but change the name to test here.
Test file.
Yeah, test file and let's do it.
So we're going to do in order to do that, we're going to do my test file.
Firstly, we're going to enter the source here.
So my test file and after that we're going to enter the destination.
And as you can see, the destination is going to be this.
So destination is going to be test file.
And here, oops, clear and L and here, as you can see here.
We have a test file.
The new with the new timestamp 315.
But here, as you can see here, whenever we copied this, this also created a new timestamp.
But the as you can see here, but the size and their contents should be the same.
So the new.
This file shows a different modification time than our previous test file.
So if a destination file already exists, the CP command may not prompt you to this fact, so it is
best to add the E option here.
So e option to force the shell to ask whether you want to overwrite a file or not.
So we will do that like this.
RLS or cp here parameter as e here and overwrite test file.
Yes.
Or E here.
And as you can see here L here you can also here.
Let's see.
And as you can see here, we override override on the test file and the timestamp and file contents
should be updated with new file here.
So if you don't answer the you here.
So here, here, the file copy doesn't process and you can also enter the n here.
So for no.
So you can also copy a file into a pre-existing directory like this will be choosing the absolute directory.
So cp.
Or clear.
Firstly, so cp e.
Uh, for example, my test file.
My test file, and we're going to do to my home, Carly And after that we will copy to, for example,
templates or yeah, downloads.
And here, let's see the two downloads.
Oops.
See the two downloads here.
As you can see here we have a new file, my test file here.
So the new file is now under the downloads directory using the same file name as the original.