Video

grep vs find in Linux: What's the Difference? | Linux Commands Explained

grep vs find in Linux: What's the Difference? | Linux Commands Explained

grep and find both search, but they answer completely different questions. find asks where is the file. grep asks where is the text. Mix them up and you get nothing useful back.

This video walks through both in a real Ruby on Rails project: locating a config file, then tracking down every place a setting is referenced.

What you will learn:
- What find does, and what it matches on
- What grep does, and what it matches on
- Why find never opens a file, and grep never filters on file properties
- How to search for a file by name, type or pattern
- How to search inside files for text or a regular expression
- What -R, -n and -i actually do, and why -R follows symlinks
- Reading grep output: the file, the line number, and the matching line
- When each command is the right one, and what each costs

Commands covered:
find . -name "payment.yml"
find config -type f -name "*.yml"
grep -Rni "PAYMENT_GATEWAY" .
grep -Rni "PAYMENT_GATEWAY" app config

Chapters:
00:00 - grep vs find: the problem
00:10 - Why developers need both
00:25 - Understanding find and grep
00:40 - How the commands work
01:00 - A practical Rails example
01:25 - Benefits and differences
01:45 - The key takeaway

One note on speed: a wide recursive search over a whole project is slow. Naming a directory, as both examples here do, is what keeps it fast. And if you mostly search source code, ripgrep is quicker than grep, but it does not replace what find does on the filesystem.

#Linux #grep #find #CommandLine #DevOps #RubyOnRails #BackendDevelopment #Terminal #SysAdmin #Bash

— #Astmation —
#software #systems, #automation, and #AI-powered #applications.
Build. Automate. Evolve.
https://astmation.com/


Watch on YouTube

Back to videos