[No audio]
Finding files and directories. Oftentimes system
administrators or system engineers or technicians,
whoever the user of Linux is, they forget where
files are located. Just like in Windows, when you
want to find out find a file, you are given a
little search box at the top of the window, and
you type in the search and looks for its file. It
takes a very long time, of course, in Windows, but
in Linux, it's a lot faster and a lot easier. So
there are two main commands that are used to find
files and directories in your system. And the
reason you need to find it, if you remember, I
gave you an example of our closet. You go into our
closet, you want to find a shirt that you haven't
been worn for a long time and you don't know where
you have it, which drawer or which shelf. You do need
to have tools to look for those files, and those
tools in Linux or find and locate. So we're going
to use those commands in our Linux
environment and do some exercises and see how they work.
[No audio]
So here we have our Linux machine, and let's find
out where we are. We are in our home directory.
And in our home directory we have files, different
files and different directory. I wanted to go into
seinfeld directory, and I want to see what's
inside of it. Inside of it, there are different
files called kramer, george, jerry, puddy, seinfeld-characters,
all those different parts. Now what if
you go back one step and you are in home
directory, and here you thought that you
created a file called kramer in this home
directory but when you come in here, you don't see
it. So you could either go into each directory one
by one, do ls command and find it which is very
cumbersome. You don't want to do it. So you could
find it by the command find. The syntax
of the command is find, and where do you want
to find it. You could give a relative path which is
dot which means in this current directory, start
the search from this current directory, and this
current directory is home/iafzal, so find dot
dash name space "kramer", and
you hit enter. It's going to tell you that the
kramer file is inside of seinfeld directory and
it's in there starting from this current
directory. So this current directory has seinfeld
directory, yes, of course. And now I know I created
that kramer file in seinfeld. Okay, perfect.
locate command works the same way. So you are in
your home directory and you want to locate kramer
This is telling you exactly where that file is.
[No audio]
find command is used sometimes to look for files
in a very hierarchical way where you have tons of
different directory, where locate is going to find
you in a short searches. So if you want to find
where, let's say our network file is where it's
located. So if you see find slash because you want
to find that network file from the root of the
file system, because you don't know where that
file is starting from which directory, so you will
always start with root space dash name, comma "ifcfg"
dash, and what is our interface. We don't know
our interface so we'll just Ctrl C and we'll do ifconfig,
and our interface enp0s3. So
find slash name ifcfg, this is the
file name of our interface, which we will cover by
the way later. And we want to find it now we are
getting all the Permission denied. Whoa, whoa,
whoa, whoa. Okay okay, relax, relax. Why are
we getting permission denied? Why didn't it find it?
Hmm. Okay, I know why. And I'm sure you guys know
why too, because you do not have permissions to go
into certain directories. So, why because you are
iafzal and who have permission to go into
different directories. Tell me, root, yes, root has
it. So you do su root, to become root, put in
the password. Now you run that command find
slash, from the beginning ifcfg dash enp, I
always forget that, sorry. Okay, so find slash
name, and ifcfg-enp0s3.
And now I'm going to run it. Now it's going
to go into every directory and look for it. The
first one is just a run directory. I suppose this
is just the process itself. So don't worry about
it, you can ignore it. Second one, you'll see it
found it. It is telling me this file that you're
looking for is in /etc/sysconfig/network-scripts/ifcfg-enp0s3.
If someone asks you, where is that file located as if
it's in just a general question, or if it's an
interview question, you know, the best way to
answer it is I will run my find command or locate
command to find where the file is located. So
practice those two commands, run man on these
commands, and look for different options that you
could use for these commands and see how easy it
could become for you.
[No audio]