0
0
Linux CLIscripting~10 mins

find command basics in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - find command basics
Start: specify directory
Check each file/dir
Apply conditions
Print/Action
More files?
NoEnd
Back to Check each file/dir
The find command starts at a directory, checks each file or folder, applies conditions, and prints or acts on matches until all are checked.
Execution Sample
Linux CLI
find /tmp -name "*.txt"
Searches the /tmp directory and its subdirectories for files ending with .txt and lists them.
Execution Table
StepCurrent File/DirCondition (-name "*.txt")ResultAction
1/tmp/file1.txtMatches *.txtYesPrint /tmp/file1.txt
2/tmp/file2.logDoes not match *.txtNoSkip
3/tmp/docsIs directoryN/ADescend into /tmp/docs
4/tmp/docs/readme.txtMatches *.txtYesPrint /tmp/docs/readme.txt
5/tmp/docs/image.pngDoes not match *.txtNoSkip
6/tmp/docs/archiveIs directoryN/ADescend into /tmp/docs/archive
7/tmp/docs/archive/notes.txtMatches *.txtYesPrint /tmp/docs/archive/notes.txt
8No more filesN/AN/AEnd search
💡 All files and directories under /tmp checked, search ends.
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6After 7Final
Current File/Dir/tmp/tmp/file1.txt/tmp/file2.log/tmp/docs/tmp/docs/readme.txt/tmp/docs/image.png/tmp/docs/archive/tmp/docs/archive/notes.txtNo more files
Match FoundNoYesNoN/AYesNoN/AYesNo
Key Moments - 3 Insights
Why does find descend into directories even if they don't match the name condition?
Because find checks directories to look inside them for matching files. The condition applies to files, but directories are explored to find matches deeper (see rows 3 and 6 in execution_table).
What happens when a file does not match the condition?
The file is skipped and not printed or acted on (see rows 2 and 5 in execution_table).
How does find know when to stop?
It stops after checking all files and directories under the starting point (see row 8 in execution_table).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the action taken at step 4?
ASkip the file
BPrint /tmp/docs/readme.txt
CDescend into directory
DEnd search
💡 Hint
Check the 'Action' column at step 4 in the execution_table.
At which step does find descend into the /tmp/docs/archive directory?
AStep 5
BStep 6
CStep 7
DStep 3
💡 Hint
Look for 'Descend into /tmp/docs/archive' in the Action column.
If the condition was changed to -name "*.log", what would happen at step 2?
APrint /tmp/file2.log
BSkip /tmp/file2.log
CDescend into /tmp/file2.log
DEnd search
💡 Hint
Check how the condition affects the Result and Action columns for matching files.
Concept Snapshot
find [path] [condition]
- Starts at path, checks each file/dir
- Applies condition (e.g., -name "*.txt")
- Prints or acts on matches
- Descends into directories to search deeper
- Stops after all checked
Full Transcript
The find command starts at a given directory and looks at each file and folder inside it. For each item, it checks if it matches the condition, like a name pattern. If it matches, find prints the file path or does an action. If the item is a directory, find goes inside it to check more files. This continues until all files and folders under the starting directory are checked. For example, searching for '*.txt' files in /tmp will print all text files found there and in its subfolders.