DCubes
Linux module

Lesson 7

Find and search

find files, grep for text, and locate programs with which.

beginner25 minRun on your machine

What you will be able to do

  • Find files by name under a directory
  • Search file contents with grep, including ERROR lines in a log
  • Use which to see which program the shell will run

Why this matters for DE and AI

On a data server you rarely remember full paths. You remember a filename (part-00000.parquet) or a word (ERROR, OOM, Timeout). find walks directories. grep walks text. Together they are how you debug without a GUI.

Concepts

find START -name 'PATTERN' lists paths. * is a wildcard.

find ~/dcubes/linux-lab -name '*.log'

grep PATTERN FILE prints lines that contain PATTERN.

grep ERROR logs/job.log

Useful flags:

Flag Meaning
grep -i Ignore case
grep -n Show line numbers
grep -R PATTERN DIR Recurse through a directory
grep -v Invert: lines that do not match

which COMMAND prints the path of the program your shell would run. type COMMAND is similar and also tells you if it is a shell builtin.

Practice on your machine

cd ~/dcubes/linux-lab
find . -name '*.sh'
find . -name '*.log'

The . means “start here.” You should see ./scripts/hello.sh and ./logs/job.log.

grep ERROR logs/job.log
grep -n ERROR logs/job.log

What you should see: the two Failed to write /data/movies/out.parquet lines. With -n, line numbers (6 and 8 if you followed lesson 5).

Search the whole lab:

grep -R INFO .

You will see INFO lines from the log. grep may also skip or mention binary files; ignore that for now.

which ls
type echo

which ls should print a path like /usr/bin/ls. type echo often says echo is a shell builtin.

Common mistakes

  • Forgetting quotes around wildcards. find . -name *.log can expand too early if a matching file is in the current directory. Prefer '*.log'.
  • grep with no file and no pipe. It will wait for you to type. Ctrl+C and add a filename.
  • Searching / as root. Do not. Stay under ~/dcubes/linux-lab here.

Next

Pipes and redirects — glue commands like a tiny pipeline.