There will be times in Linus where you create a file
and maybe you forget where the directory was.
Sometimes you need to find log files
or locations of different commands, anything.
Linux comes with a lot of different commands
that will allow you to execute these searches.
So the first one I want to look at is locate,
just really quick.
We're just trying to locate anything relative to backup.
And we see it gives us a huge list
of any file name that has the word backup in it.
And there's different options with that, right?
We can make sure that this is case insensitive.
So do I.
Another thing we can do is,
make sure that we actually just get a count.
We just want to know how many.
Now it gives us a number there.
Now, the one I'm going to focus on the most today
is the find command.
This is clearly the most powerful one of them all.
This allows us to do any structure that we like.
To locate, we can't pick the file directory
that we're looking into,
it's just going to search the whole system.
This allows us to search,
if we're looking for a type of directory, type of file,
just a lot of different options for us.
So you see on this one,
we're looking for a directory with anything
with the name log but only directories.
So it starts from the route directory,
and it recursively searches every sub-directory
for anything with log, as a directory name.
Next, we're going to do the same thing,
but we're going to look for a file.
Starting from the route directory,
so we got to do the type, it's going to be file,
that's what the F stands for,
the name from the messages.
And now we see we have a file named messages
under the VAR log sub directory.
We can also look up files by certain sizes.
For example, we're going to use it one more time,
but we're going to look up any file,
in this particular file location,
so we're going to use the VAR log,
that's larger than a hundred kilobytes.
Okay. So let's do this.
Type: it's going to be a file.
Strings.
So this gives us complete list
of every file that's larger than a hundred kilobytes.
And now we can test this out just by making sure.
So we'll, let's take this out,
Make it readable.
And now we see this particular file is 287 kilobytes.
If you want to just test one more.
For good measure.
Again, this one is 321 kilobytes.
Now, along with sizes, you're also able
to search for things that have been updated
within a certain amount of time passing.
So we're going to look for a type
of file that's been updated within the last 30 minutes.
So again, we'll look in the same directory.
Log for a file,
and then we're going to look for right here
30 minutes.
So all of these files have been updated
within the past 30 minutes.
Again, we're just going to verify this.
Look up for our log.
Let's just do the secure.
Now it's updated at 12:40.
And if you look at the top of my screen,
you'll see that it's currently 12:49,
so that's within range.
You can also look for an either
or type of clause attached to this command.
So we're going to look for a file in our log.
We wanted it to either be zero
or is sized to be greater than a hundred kilobytes,
and last been updated within the last 30 minutes.
So this search function accomplishes all of these,
and we're just going to verify one of these.
So I'm going to list this out really quick.
The list command, use the VAR log, just file.
And we can see this was one that's selected
because it's an empty file.
Again so we just went over a few
of the search commands in Linux.
Now the locate command requires the database to be updated
in order to perform accurate searches, but the font is not.
And the font also allows us
to search particular directories.
So it has a lot of advantages over the locate
but the locate can be faster, but of course it
won't represent the entire disc versus the find command.
And I'll see you in the next lesson.