This course has been updated! We now recommend you take the Full Stack for Front-End Engineers, v3 course.

Check out a free preview of the full Full Stack for Front-Ends Part 2 course:
The "Find: Exercise" Lesson is part of the full, Full Stack for Front-Ends Part 2 course featured in this preview video. Here's what you'd learn in this lesson:

Jem walks through some examples of how to use find, and why mastering this command can be extremely useful.

Get Unlimited Access Now

Transcript from the "Find: Exercise" Lesson

>> Jem Young: So let's do an exercise with Find. How, knowing the syntax, how do we find all the log files in/var/log/? Think about it, you can even run the commands locally, it's not gonna break anything, hopefully. How would I find all the log files? Well, I would use find, the directory, the type, f is file.

[00:00:26] Otherwise I search file names and directory names. We just want files. We give it a name, wildcard *.log. And if you run that, you might need to see the command cuz /var/log/ is not owned by you.
>> Jem Young: So let's go ahead and do that. find /var/log/, and I wanna say type is file and name, say all the log files, *.log.

>> Jem Young: And there's a lot of log files. Now, if we wanna say, I wanna find all the log files in my system in general, you can just say /var. Pretty fast, but most things are in /log. If you're saying, why are we getting permission denied, it's because we don't have as this user permission to even read a lot of the files.

>> Jem Young: So if I run that again we see, permission denied. Remember our old trend sudo bang bang? It means run the last command as sudo, and now we can read all the log files.
>> Jem Young: All right. I feel like not enough people are, their minds are being blown.

[00:01:37] I know, it's find, it's simple but when you break down most computer science, it's actually pretty simple. It's finding things, writing things, reading things and writing things to a database. It's kind of what it all boils down to. And the ability to quickly find things, if you master find, you'll just impress your friends, impress your colleagues.

[00:01:54] You're like, I know where that is, cuz you can find things by modified time. You can say, what are all the files in my system that have been touched in the last day? That's pretty useful. Trying to do that with any other system or any other like find command would be pretty difficult.

[00:02:06] It's hard to do it. You can say, find all the files that are modified by this user in the past week in case someone broke into your system, did something malicious. That's pretty useful. Again, find and grep are two of the most used command people know, other than vim.

[00:02:20] That's also useful too, and Nmap. So let's find all the empty files in /etc. How would we do that?
>> Speaker 2: Size zero, size.
>> Jem Young: That's a good point, size zero. But remember back here, we have an option that says empty. So knowing what we know about find, where in our options.

[00:02:51] How do we find the empty files? Just think about it mentally, you can type it up. It's actually pretty straightforward, find /etc -type file -empty.
>> Jem Young: That's useful. You say, Jem, why would I need to find the empty files in my system? Well, let's say you have a bunch of log files that are created by some rogue process and you wanna clean them up.

[00:03:15] This is a great way of finding them. Just like that, versus before, think about trying to find an empty file system without knowing about find. You have to go through all the directories, you say, what's the file size? We can do it with find with one command, pretty useful.

[00:03:29] If you don't think it's useful, you will in the future, trust me. All right, let's find all directories with the word log in it. How do we do that? So we say find /log, so it's a directory, so we want type d, and the word log in it, we just say name log.

[00:03:53] Am I right? Yes, I like when I'm right, because I don't remember all these things off the top of my head. So just find, type, directory, name log.
>> Jem Young: These are pretty useful, but again, think of all the scenarios that you ever try to find something in your file system, and I almost guarantee you can a find.

[00:04:13] It might take a bit more verbose typing, but when you finally see the brilliance of it, you're like, this makes sense. This is awesome.