So, that's pretty neat. We can also do it for different file names, not just
extensions. So, if I were to run "find" in the current directory, ". -type f" and let's
use "-iname", and I've got a few files with the word "file" in them so
I'm going to type "file*" and it's going to return all the
different files that I've got. So, you can use this in a more practical application,
this is just an example, but let's type
"find /etc -type f -iname "*.conf"" and this will
find all configuration files and it is a recursive function, and so you'll notice
that there's a directory here "systemd" inside of /etc that has
configuration files in it, and so it spits out all configuration files. This
is useful if you are looking for all files of certain type, but also here's an
interesting thing I'm just gonna clear this out here, so now let's use the find
command to find files that have certain permissions.
So, how we're going to type this command is, first I'm gonna type "ls -l" and
we're going to see that all the files in this directory are read-write, read-write,
read, and this permission scheme translates to the numerical value of 664.
So, what we're gonna do is type "find . -type" and so
-type can...you don't even need to include this, so if you omit the type
flag it's just going to find files or directories, if you type "-type f"
it's only gonna find files, and if you replace the "f" with a "d" it's only gonna
find directories.
We're only working with files anyway so I'm gonna through this in there, and then we're going
to use the "-perm" argument, and we're going to "0664" because those are the
permissions on this file, and what it's gonna do is gonna spit back the output
which in our case is all of these files. You can also search based on file size.
So, again type "find ." for the current directory, and we're gonna type
"-size" and here you can put for instance "+100k"
If you're looking for an exact file size you can use that, or maybe one
megabyte, anything over one megabyte, and you can see how this command would be
useful, it wouldn't be useful in our case right here because we've got you know
small files. Maybe, type "find . -size -1m" not sure if it can do this, but anything under a megabyte,
cool. So, you can search more than or less than and then your search parameter.
Let's clear this again. You can also use a not operator. So, let's say and this is good
because you can get so far using using the find command, let's say I wanted to
find all files that have an "-iname "*.php" which is not case-sensitive so it's
gonna find all of the .php files regardless of the case that was used in
the extension, but let's say I want to find all files that are not .php. Let's
say I've got a bunch image files, and text files, and other
java script files, let's say, and I just want to find everything that's not .php. What I would
do is type "find ." in the current directory,
"-type f"
"-not" and then the argument, "iname" "*.php" and this is
gonna spit back all the files that don't fit that criteria.