[No audio]
File Maintenance Commands. In this lesson, we will cover
a few of the commands that are used to
maintain or keep or change your files.
Some of the commands are listed here.
The first one is the copy command,
cp, which copies one file to another.
The second one is to remove a file which is, rm.
The third one is move,
this command is used to move the location of a file
from one location to another or to rename a file.
So it does two things or it serves two purpose.
Then we have mkdir which is to make directory and then
rmdir to remove a directory or there's another way to remove
a directory by typing rm -r or hyphen r.
Then we have change group which is the ownership
of a file at the group level, and then
we have change ownership which is the ownership of
the file at the user level.
Some of the commands we have already covered and some
of the commands we will be covering in this lesson.
So let's go to our Linux machine and go over these
commands one by one,
[No audio]
and let's log into our machine.
We already have the last screen open.
Let's clear this out.
Where are we?
We are in etc.
When you type cd, and hit enter, and then pwd,
now you are back in your home directory.
Clear the page,so this way you will start fresh.
Now the first command that
we will be learning is cp.
Again cp is a copy command.
You could find out by hitting man and cp.
This will tell you cp copy files and directories.
So the way you could do it in Windows is you
right click on a file and you get the option of
copy and then you go to another file, another directory or
another location and then right click and do the paste. In Linux,
this is how it works.
We will, let's look at our listing.
We have all these files.
So now we will copy the file called george
and we will name it to a different name,
let's say another character of the show
david, and you hit enter.
So this will tell you that cp space source which
is the george, and the destination which is the david.
You hit enter, then you do ls -ltr.
The tr option will give you the newest
file created at the bottom, hit enter.
So the david file is created. If you also notice,
the george file is still there, and it created a
file, copied the file george and renamed it david.
We could also add something to the file
as let's say echo
[No audio]
david puddy,
[No audio]
is Eliane's boy friend
[No audio]
and then we'll output to david, and hit enter.
And how do you verify it?
You do cat david.
You will see the contents in there.
That's what you do the copy for, you could
also do, is you copy david, and then you
can copy it not at this location where you
are, you could copy it some other location.
Let's say we wanted to copy into tmp location.
So it is going to copy it.
It's now going to remove that file.
It will copy it to the tmp directory.
Hit enter, do ls -ltr.
You'll see it has the david
copy, the original copy here.
Now we will go to /tmp, and then we will
do ls -ltr at the bottom to see the file is there.
See the same file that we copied
but it's in a different location,
and it is owned by me,
owned by the same group as myself,
and it has same number of bytes.
You could do cat and david to
see what's inside of the file.
So which directory you are in?
We are in tmp directory.
If you want to go back to
our home directly, just simply type cd,
hit enter, pwd, and you are
back in your home directory, ls -ltr.
And that's where you have your
all the files. That's about the copy.
You could practice that copy command by
copying different files or different names,
whichever names that you like.
The next command we're going to learn is remove.
Let's create another file touch,
and we will create a new file in homer, bard, marge,
lisa, and we call another file apoho.
apoho is another character of Simpsons family.
So we'll create this file called apoho.
And we will do ls -ltr,
and you'll see it created a file apoho.
If you want to append a file or add
something to that file, what do we do?
We do echo, apoho is an indian character in the show.
Right. So I'll put that to where, apoho.
How do you verify that, apoho, apoho an indian character in the show.
That's how you do it. Now you want to remove this file. Now,
after certain times you don't need it.
So what you do, you do rm apoho, simply
as that, hit enter, and it's gone. Let's try,
let's make sure it's gone or not. Yes.
See there is no such file apoho in our directory,
because we removed it.
We could also remove a directory,
but we'll cover that when it's turns going to come.
The next command we have to learn is move.
Now move command,
actually move the file from one location
to another and also rename the file.
How does it work? Let's call lex, in Superman
there is this character,
of course it's a villain character, lex. So let's see,
we have the lex.
Yes, we have there.
We wanted to rename that to luther.
So lex, last name was luther. So let's try,
we wanted to change to Luther. So how do we do it?
We do mv lex, and this is of course the source,
and what's the destination name you want to give it to,
luther, luther.
This is going to rename this
file within the same directory.
Hit enter, ls -ltr,
and here you see luther.
So this is how you rename it.
If you wanted to rename any
other file, you could do that,
or you wanted to create a
different file, you could do that.
Let's say we have this file called david,
and we want to change to the last name
of course, which is mv david to puddy.
So that's his last name.
So we are moving david to the name puddy.
Let's ls -ltr.
It changed the name from david to puddy,
but it kept the content of that file, which was if
you do cat, you'll see david puddy is Eliane's boy friend.
So it just changed the name.
It didn't change the content.
Next one, by the way, also to change the location
is if you wanted to move puddy from this location
to a different location, let's say to tmp, it will
move that file to a different location tmp.
Now let's see do we still have that file?
No, we don't. Where did it go?
We moved it to tmp.
So how do we know it moved to tmp?
You do cd into tmp, ls -ltr.
See, this is the puddy file that you created.
Now let's move puddy back to our home directory.
And what is our home directory?
You guys should know that home,
your username, and hit enter.
It should bring you back to your home directory.
When you do cd, hit enter,
it will bring you back to your home directory.
Do ls -ltr, and your puddy file is back.
Next one is make directory.
It's simply we will make mkdir gameofthrone, one of the biggest show,
how's that. We created this,
this is how the new directory is created mkdir.
Now let's try command which is remove directory.
So remove directory,
if you want to delete one of
these directories from your home directory,
let's say I wanted to remove gameofthrone directory.
You just simply type rmdir gameofthrone,
and it is gone.
This is one way to remove it. Another way to remove it,
in order for us to remove it, let's recreate it again,
hit up arrow key, and you will
get back to the same command.
mdir gameofthrone, the directory is created.
Another way to remove it is rm -r gameofthrone, and it is gone.
[No audio]
All right. Next command we have change group.
Changing group is changing the ownership of the file,
changing the ownership of a group of a file.
And the last command is changing
the ownership of a file.
So if I wanted to change the ownership of file
puddy and I wanted to change it to group called
root, so we will do chgrp root puddy.
It says, Operation not permitted. Why?
Because who we are, we are ourselves.
And who can make these changes?
If I wanted to assign something to
root, I have to be root.
So let's become root.
[No audio]
Once you're root, let's go back to our home directory.
[No audio]
And now what we'll is do chgrp root puddy.
And this time it worked, because we have all
permissions in the world we could think of.
Now, next command change ownership to root of puddy.
This will change the ownership of the
file name puddy to root as well.
Now, if you wanted to do both commands at once
so chown, you could do, iafzal:iafzal puddy.
So what this command will do, it will change the ownership
as well as group ownership of the file name puddy.
Hit enter, ls -ltr, and there you go.
You got your file back with the
original permission or original ownership permission.
So these are the file maintenance command.
Once again the recap, cp, rm, mv, mkdir,
rmdir, chgrp, chown.
[No audio]