0
0
Linux CLIscripting~10 mins

find by modification time in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - find by modification time
Start: User runs find command
Check each file's modification time
Compare mod time with given criteria
Print file
Repeat for all files
End
The find command checks each file's modification time and prints files matching the time criteria.
Execution Sample
Linux CLI
find . -mtime -2 -print
Find files modified in the last 2 days and print their paths.
Execution Table
StepFile CheckedModification Time (days ago)Condition (-mtime -2)Action
1./file1.txt11 < 2 (True)Print ./file1.txt
2./file2.log33 < 2 (False)Skip ./file2.log
3./subdir/file3.md00 < 2 (True)Print ./subdir/file3.md
4./oldfile.bak1010 < 2 (False)Skip ./oldfile.bak
5No more files--End of search
💡 All files checked, command ends.
Variable Tracker
VariableStartAfter 1After 2After 3After 4Final
Current File-./file1.txt./file2.log./subdir/file3.md./oldfile.bakNo more files
Modification Time (days ago)-13010-
Condition (-mtime -2)-TrueFalseTrueFalse-
Action-PrintSkipPrintSkipEnd
Key Moments - 3 Insights
Why does the command print some files but skip others?
Files are printed only if their modification time is less than 2 days ago, as shown in rows 1 and 3 of the execution_table where condition is True.
What does '-mtime -2' mean exactly?
It means files modified less than 2 days ago. The execution_table shows this by comparing each file's mod time to 2.
Why does the command stop after checking all files?
Because find checks every file once. The last row in execution_table shows 'No more files' and ends the search.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what action is taken for './file2.log'?
APrint the file path
BSkip the file
CDelete the file
DModify the file
💡 Hint
Check row 2 under the 'Action' column in execution_table.
At which step does the condition '-mtime -2' become false for the first time?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Condition (-mtime -2)' column in execution_table rows.
If we change '-mtime -2' to '-mtime -5', what happens to the action for './oldfile.bak'?
AIt will be printed
BIt will still be skipped
CIt will be deleted
DIt will cause an error
💡 Hint
Consider that 10 < 5 is false, but 10 < 5 is false, so check how condition changes with -5.
Concept Snapshot
find . -mtime N
- Finds files modified exactly N days ago.
-mtime -N finds files modified less than N days ago.
-mtime +N finds files modified more than N days ago.
Use -print to show matching files.
Example: find . -mtime -2 -print finds files modified in last 2 days.
Full Transcript
The 'find' command with '-mtime' option checks each file's modification time. It compares the file's age in days to the given number. If the file was modified less than the specified days ago (using -mtime -N), it prints the file path. The command repeats this for all files in the directory tree. When no files remain, the command ends. This visual trace shows each file checked, its modification time, whether it meets the condition, and the action taken. Beginners often wonder why some files print and others don't; this is because of the time comparison. The '-mtime' option is a simple way to filter files by age in days.