Instructor: In my current working directory, I have an images folder. The images folder has several images in it, as you can see. Let's say that I wanted to find all of the PNGs in the folder. To do that, I would use the find command. I'll pass the images folder, and then I'll pass the name flag, and I'll do wildcard.png.
This might look like a regex, but it's not, actually. This is just a string that supports some special characters that do matching, so this will match any file name that ends with .png.
Let's run that. We can see it finds those two PNG files. If we do the same thing for JPGs, we can see it just returns that one, but we have two JPEGs in there.
Instead of using name, we can use iname. The iname is a case-insensitive name search. If we run that now, we can see this one is returned, as well.
Another useful one, for example, is if we do find. If I just wanted to find all folders in my current working directory, I would pass type D, and that'll return the images folder we just looked at.
I have another folder in here called dist, so we can just confirm that with the list here. We can combine type with name. If I wanted to find all folders named images, that would work, and just returns the one here.
Find also supports running an action on each match. For example, in my dist folder, I have two JS files, and then an image file.
If we want, we can get more custom, too. For example, if I wanted to run an image compression and optimization tool on each of the matching images, I could do that.
I do find images. I'll do name, and I'll just run this on the PNGs. I'll pass the exec flag. That lets us run an arbitrary command on each match.
I have a tool called pngquant that I have installed previously. Pngquant just optimizes PNG files and makes them smaller.
Find supports this special character. The two curly braces stand further from each matching file.
To end this little expression, you have to do your backslash, and then semicolon. Strange syntax, but if we run that, and then let's list out images, we can see that it worked. Pngquant, I've created these two optimized image files.
Find's a really handy tool. Refer to the documentation on it for more possibilities. The easy way to look at the documentation is if you run man-find. Man stands for manual, and so this will bring up all of find's options right here in your terminal.