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 "Grep: 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:

Grep is another powerful command to help you search your server. Jem illustrates some examples of how to use grep to help you find content within your files.

Get Unlimited Access Now

Transcript from the "Grep: Exercise" Lesson

>> Jem Young: So let's move on to Grep, finds files. Grep helps me look inside the files. The general formula is, grep, the options, the search expression, and where we wanna search. So let's say you have some code that you modified and you're getting repo, and you need to free the code itself, that's where you use grep.

[00:00:23] Find the files and you pipe it in the grep. And we will be piping things in the grep later in the day, and you'll see how useful grep is. But it's just global regular expression. I will tell you I am not great with regular expressions, I know a little bit but if you're really, really good at regular expressions, you know the things you can do.

[00:00:42] You can validate email addresses in one line, you can do lots of powerful things. For now I just use string searches.
>> Jem Young: Bonus tip. Let's say you wanna search a inside a gzip file, zgrep will search inside a gzip file for you, which is pretty useful actually. Because by default, most log files get compressed after certain amount of time.

[00:01:03] Let's say we still wanna search inside those log files for information, zgrep is where you wanna go. So it's the same as regular grep, just put a z on it, for zipped. Makes sense, again, they're naming is just so on point there. So this one's always useful. If we wanna find the running node process, and this is a command I use all the time because I run Node at work.

[00:01:28] Netflix UI is built largely on Node, at least the website is. And I have Node processes that are just eating at that memory and I wanna find out where they are. So if I say ps aux, just saying these are the file, what's running right now right now for my user that I've permission to read.

[00:01:43] Then we're just gonna look for Node. So I'm just gonna do that right now. So this is back on my local machine. Clear this all out. Set ps aux, and we've run this by default. That's a lot of information. This is why we can pipe it to grep.

[00:01:59] So if I say, grep node, and am I running an instance? Yes, I'm not running an instance, this is just returning the instance of grep that I'm running, it's come full circle. But it's extremely useful because with grep, you get all this verbose output and you get just the things that you're looking for.

[00:02:18] Let's say I wanna find instances that are running by me Jem Young, the user. And it's gonna return all that for me. Not as useful because I'm the one running the machine. But ps aux and grepping something is probably one of the fastest way to tell what sort of processes are running on your computer.

[00:02:36] For your nginx process, your MySQL server, you can see all those instances. And in many instances you find zombie processes. You say, I didn't I was running a PostgreSQL server at this point. Maybe you were and you just forgot about it. ps aux and then greppng that, super, super useful.

[00:02:55] All right, everybody believe in power for grep and find?
>> Jem Young: Only a few people. You will, you'll believe by the end.