0
0
Linux CLIscripting~10 mins

find by name, type, and size in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - find by name, type, and size
Start: User runs find command
Parse options: name, type, size
Search directory tree
Check each file/directory
Match name?
All conditions met?
Yes
Print file path
Continue until all files checked
End
The find command checks each file in the directory tree against name, type, and size filters, printing paths that match all conditions.
Execution Sample
Linux CLI
find . -name "*.txt" -type f -size +1k
Find all regular files ending with .txt larger than 1 kilobyte in the current directory and subdirectories.
Execution Table
StepFile CheckedName MatchesType MatchesSize MatchesPrint Path?
1./notes.txtYes (*.txt)Yes (file)No (500 bytes)No
2./report.txtYes (*.txt)Yes (file)Yes (2k)Yes
3./image.pngNo (*.txt)Yes (file)Yes (5k)No
4./docsNo (*.txt)No (directory)N/ANo
5./docs/manual.txtYes (*.txt)Yes (file)Yes (3k)Yes
6./script.shNo (*.txt)Yes (file)Yes (1.5k)No
7./archive.zipNo (*.txt)Yes (file)Yes (10k)No
ExitAll files checked---Stop searching
💡 All files in the directory tree have been checked against the conditions.
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6After 7Final
Current FileNone./notes.txt./report.txt./image.png./docs./docs/manual.txt./script.sh./archive.zipAll checked
Name MatchN/AYesYesNoNoYesNoNoN/A
Type MatchN/AYesYesYesNoYesYesYesN/A
Size MatchN/ANoYesYesN/AYesYesYesN/A
Print PathN/ANoYesNoNoYesNoNoN/A
Key Moments - 3 Insights
Why does the file './notes.txt' not get printed even though its name and type match?
Because its size is 500 bytes, which does not meet the condition '-size +1k' (greater than 1 kilobyte), as shown in execution_table row 1.
Why is the directory './docs' not printed even if it contains matching files?
Because the '-type f' option filters only regular files, so directories like './docs' are skipped, as seen in execution_table row 4.
What happens if a file matches name and size but not type?
It will not be printed because all conditions must be met; type mismatch causes rejection, as shown in execution_table row 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, which file is the first to be printed?
A./notes.txt
B./image.png
C./report.txt
D./docs/manual.txt
💡 Hint
Check the 'Print Path?' column for the first 'Yes' value.
At which step does the condition '-size +1k' first become true?
AStep 1
BStep 2
CStep 4
DStep 6
💡 Hint
Look at the 'Size Matches' column in the execution_table.
If the '-type f' option was removed, which file would then be printed at step 4?
A./docs
B./image.png
C./script.sh
D./archive.zip
💡 Hint
Step 4 is './docs' which is a directory; without '-type f', directories can match.
Concept Snapshot
find [path] -name "pattern" -type [f/d] -size [+/-]size
- Searches files/directories recursively
- Filters by name (wildcards), type (file or directory), and size
- Prints paths matching all conditions
- Size +1k means larger than 1 kilobyte
- Use '.' for current directory
Full Transcript
The 'find' command searches through directories and files starting from a given path. It checks each item against conditions like name pattern, type (file or directory), and size. Only items matching all conditions are printed. For example, 'find . -name "*.txt" -type f -size +1k' finds all regular files ending with .txt larger than 1 kilobyte in the current directory and its subdirectories. The execution table shows step-by-step how each file is checked and whether it matches each condition. Variables track the current file and match results. Key moments clarify why some files are not printed despite partial matches. The visual quiz tests understanding of the matching process and conditions. This helps beginners see how 'find' works in practice.