How to locate files and folders on Linux systems
Environment
Linux systems (Ubuntu, Rocky Linux, etc.)
Issue
Locate files or folders on Linux systems
Find accidentally moved files or directories
Need to find recently modified files (e.g., files modified today or yesterday)
Resolution
Basic file and directory search
The find command is available on all Linux systems without additional installation. Basic syntax is: find [path] [options]
Search for files or directories by name:
$ # Search for files/directories named "report.txt" starting from current directory
$ find . -name "report.txt"
./project/report.txt
./backup/report.txt
$ # Search with wildcards (use quotes)
$ find . -name "*report*"
./documents/annual_report.pdf
./reports/monthly_report_2024.xlsx
./backup/old_reports/
$ # Case-insensitive search
$ find . -iname "*report*"
./documents/annual_report.pdf
./reports/Monthly_Report_2024.xlsx
./files/REPORT.txt
Note
The dot . means current directory. Use ~ to search from home directory, or / to search entire system (requires more time).
Search only files or only directories:
$ # Search only files
$ find . -type f -name "*report*"
./documents/annual_report.pdf
./reports/monthly_report_2024.xlsx
$ # Search only directories
$ find . -type d -name "*backup*"
./backup/old_reports/
./data/backup/
$ # Search for a directory named "data"
$ find . -type d -name "data"
./projects/data
./analysis/data
./archive/old_project/data
Search with file extensions:
$ # Find all Python files
$ find . -type f -name "*.py"
./scripts/process_data.py
./tools/helper.py
$ # Find all PDF files
$ find . -type f -name "*.pdf"
./documents/manual.pdf
./reports/summary.pdf
Finding recently modified files
Find files modified within a specific time period:
$ # Files modified in the last 24 hours (today)
$ find . -type f -mtime -1
./data/output.csv
./logs/application.log
./workspace/notes.txt
$ # Files modified in the last 7 days
$ find . -type f -mtime -7
./reports/weekly_summary.xlsx
./data/recent_analysis.csv
$ # Files modified more than 30 days ago
$ find . -type f -mtime +30
./archive/old_data.csv
./backup/legacy_files/document.txt
Note
-mtime -1means modified less than 1 day ago (within last 24 hours)-mtime +30means modified more than 30 days ago-mtime 7means modified between 7 and 8 days ago
For more precise time control (minutes):
$ # Files modified in the last 60 minutes (1 hour)
$ find . -type f -mmin -60
./logs/application.log
$ # Files modified in the last 10 minutes
$ find . -type f -mmin -10
./workspace/current_work.txt
Combining search criteria
Combine name patterns with time filters:
$ # Find PDF files modified in the last day
$ find . -type f -name "*.pdf" -mtime -1
./reports/daily_report_2024-12-20.pdf
$ # Find Python files in scripts directory modified in last week
$ find ./scripts -type f -name "*.py" -mtime -7
./scripts/new_feature.py
./scripts/bugfix.py
$ # Find log files older than 7 days
$ find . -type f -name "*.log" -mtime +7
./logs/application.log.2024-12-01
./logs/access.log.old
Limit search depth:
$ # Search only in current directory (not subdirectories)
$ find . -maxdepth 1 -name "*report*"
./report.txt
$ # Search only 2 levels deep
$ find . -maxdepth 2 -type f -name "*.txt"
./notes.txt
./documents/readme.txt
Exclude specific directories:
$ # Exclude .git and node_modules directories. -prune is more efficient.
$ find . \( -path './.git' -o -path './node_modules' \) -prune -o -type f -name "*report*"
./src/report_generator.py
./docs/report_template.md
Practical examples for finding missing files
Common scenarios for locating files:
$ # Find all files modified today in home directory
$ find ~ -type f -mtime -1
$ # Find a file you worked on yesterday (more precise)
$ find ~ -type f -daystart -mtime 1 -name "*presentation*"
$ # Find all Excel files in home directory
$ find ~ -type f -name "*.xlsx" -o -name "*.xls"
$ # Find large files (bigger than 100MB) modified this week
$ find . -type f -size +100M -mtime -7
$ # Find files owned by specific user
$ find . -type f -user username
Root Cause
Files may appear missing on Linux systems due to:
Accidentally moved to different directory
Saved with slightly different name than expected
Located in unexpected subdirectory
Hidden files (starting with dot
.)
The find command is a standard Unix tool that:
Comes pre-installed on all Linux systems
Recursively searches directory trees
Supports complex search criteria
Can perform actions on found files
While the syntax may seem complex initially, find is powerful and universally available, making it the most reliable tool for file search on Linux systems.
References
findmanual: Useman findfor complete documentationCommon
findexamples:find --help