>_ IzzyLab

Hands-on task

This task is step 19 of the course “find and xargs: search and bulk operations”

find + xargs grep

medium~5 min

Under /root/src (including subdirectories) there are many files. Find the .txt files that contain the word TODO and write their full paths (/root/src/…, one per line) to /root/todo.txt. Use a find … | xargs grep pipeline. Don't include files with other extensions in the list.

What you'll practise:
  • find
  • xargs
  • grep -l
  • pipeline
  • searching file contents

Topic breakdown

The classic "find files — process their contents" combo: find selects files by name/type, and xargs passes them in batches to an external command — here grep. The grep -l (list) option outputs only the names of files with a match, which is handy for reports and further automation. For robustness against unusual names, -print0/-0 is used. The alternative is find -exec grep -l {} +, but xargs is often shorter and lets you add -P for parallelism.

What's checked

  1. all .txt files with TODO found
  2. no extra files

What it looks like