0Pricing
DevOps Bootcamp · Lesson

Searching for Files (find, grep)

Discover powerful commands like 'find' and 'grep' to locate files and specific text patterns within files across your system.

Searching for Files (find, grep) is a free DevOps Bootcamp lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Search in Linux?

Finding files and text is a daily task in Linux. Imagine needing to locate a specific configuration file or a line of code in a large project!

We'll learn two powerful commands: find for locating files/directories, and grep for searching *inside* files for text patterns.

Meet the `find` Command

The find command searches for files and directories in a directory hierarchy. It's super flexible!

Its basic structure is: find [path] [expression]. The [path] tells find where to start looking, and [expression] defines what to look for.

Finding Files by Name

The most common way to use find is to search by name using the -name option. You can use wildcards like *.

Let's find all files ending with .txt in the current directory.

cd /tmp
touch report.txt document.pdf notes.txt
find . -name "*.txt"

Finding Files by Type

You can specify what kind of entry find should look for using the -type option:

  • f for regular files
  • d for directories

Let's find all directories in the current location.

cd /tmp
mkdir mydir anotherdir
touch file.txt
find . -type d

Finding Files by Size

Need to find large files? Use the -size option. You can specify units like c (bytes), k (KB), M (MB), G (GB).

  • +10M: larger than 10MB
  • -5k: smaller than 5KB
  • 100c: exactly 100 bytes

Find files larger than 1KB.

cd /tmp
dd if=/dev/zero of=small_file bs=100 count=1 2>/dev/null
dd if=/dev/zero of=large_file bs=2k count=1 2>/dev/null
find . -size +1k

Introducing `grep`

While find locates files, grep (Global Regular Expression Print) searches *inside* files for specific text patterns.

Its basic syntax is: grep [pattern] [file...]. The [pattern] is the text you're looking for, and [file...] are the files to search in.

`grep` for Simple Text

Let's create a simple text file and use grep to find a word within it. grep will print every line that contains the pattern.

cd /tmp
echo "Hello CoddyKit learners!" > greeting.txt
echo "This is a great lesson." >> greeting.txt
echo "CoddyKit is fun." >> greeting.txt
grep "CoddyKit" greeting.txt

`grep` Options: -i and -n

Two handy options for grep:

  • -i: Ignore case during the search.
  • -n: Show the line number where the match was found.

Let's find "coddykit" (case-insensitive) and see line numbers.

cd /tmp
echo "Hello CoddyKit learners!" > greeting.txt
echo "This is a great lesson." >> greeting.txt
echo "coddykit is fun." >> greeting.txt
grep -i -n "coddykit" greeting.txt

Combining `find` and `grep`

You can combine find and grep to search for files *and* their content. The -exec option of find lets you run another command on each found file.

Here, we find all .txt files and search for "CoddyKit" inside them.

cd /tmp
echo "Hello CoddyKit" > file1.txt
echo "Hello World" > file2.txt
echo "CoddyKit rocks" > file3.txt
find . -name "*.txt" -exec grep -l "CoddyKit" {} +

Quick Check

You have a directory with several files. Which command would find all files named log.txt or error.log that are larger than 50KB?

Recap: Searching Files

Great job! You've learned how to efficiently search for files and their content in Linux:

  • find: Locates files and directories based on various criteria like name, type, and size.
  • grep: Searches *inside* files for specific text patterns, with options for case-insensitivity and line numbers.
  • We also saw how find and grep can work together for powerful content discovery.

Keep practicing these commands to master your Linux navigation skills!

Frequently asked questions

Is the “Searching for Files (find, grep)” lesson free?

Yes — the full text of “Searching for Files (find, grep)” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Searching for Files (find, grep)”?

Discover powerful commands like 'find' and 'grep' to locate files and specific text patterns within files across your system. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Searching for Files (find, grep)” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Viewing File Content (cat, less, head, tail)
  2. Understanding File Permissions (chmod, chown)
  3. Searching for Files (find, grep)
  4. Creating Links: Hard Links & Symlinks
← Back to DevOps Bootcamp