Basic Time-Based Examples
1. Find files modified in the last 24 hours
find /home/user/documents -type f -mtime 0
/home/user/documents/report.txt
/home/user/documents/notes.md
Finds regular files in the specified directory that were modified within the last 24 hours.
2. Find files modified exactly 2 days ago
find /var/log -type f -mtime 2
/var/log/syslog.2.gz
/var/log/auth.log.2.gz
Finds files that were modified exactly 48-72 hours ago (2 days ago).
3. Find files modified more than 7 days ago
find /tmp -type f -mtime +7
/tmp/old_file.tmp
/tmp/cache/obsolete_data.cache
The +7 finds files modified more than 168 hours ago (7 days).
4. Find files modified within the last 2-7 days
find /backups -type f -mtime +1 -mtime -7
/backups/db_backup_3days.tar.gz
/backups/files_5days.zip
Combines conditions to find files modified between 2 and 7 days ago.
5. Find files accessed in the last hour
find /home/user -type f -amin -60
/home/user/.bash_history
/home/user/downloads/recent_file.pdf
Uses -amin (access time in minutes) to find files accessed in the last 60 minutes.
More Time-Based Examples
6. Find files not accessed in over 30 days
find /var/www/html -type f -atime +30
/var/www/html/old_page.html
/var/www/html/images/archived.png
Uses -atime (access time in days) to find files not accessed in over 30 days.
7. Find files changed (metadata) in last 30 minutes
find /etc -type f -cmin -30
/etc/hosts
/etc/resolv.conf
Uses -cmin (status change time in minutes) to find files whose metadata was changed recently.
8. Find directories modified in last 48 hours
find /home -type d -mtime -2
/home/user/new_project
/home/user/documents/work
The -type d option limits the search to directories only.
9. Find files newer than reference file
find /data -type f -newer /var/log/timestamp.txt
/data/recent_log.log
/data/current_data.dat
Finds files that are newer than the specified reference file.
10. Find files older than reference file
find /archive -type f ! -newer /var/log/timestamp.txt
/archive/old_data.tar
/archive/backup_2023.zip
The ! operator negates the condition, finding files older than the reference.
Advanced Time-Based Examples
11. Find files modified exactly 1 hour ago
find /var/tmp -type f -mmin 60
/var/tmp/hourly_job.tmp
Finds files modified exactly 60 minutes ago.
12. Find files modified more than 2 hours ago
find /cache -type f -mmin +120
/cache/old_session.cache
/cache/temp_data.old
Finds files modified more than 120 minutes ago.
13. Find files accessed within last 10 minutes
find /tmp -type f -amin -10
/tmp/recent_process.pid
/tmp/lock_file.lock
Finds files accessed in the last 10 minutes.
14. Find files with status changed in last day
find /etc -type f -ctime -1
/etc/passwd
/etc/group
/etc/shadow
Finds files whose metadata (permissions, ownership, etc.) changed in the last 24 hours.
15. Find files modified today and delete them
find /tmp -type f -mtime 0 -delete
(No output if successful, files are deleted)
Combines time-based finding with the -delete action.
Practical Usage Examples
16. Find files older than 90 days and list details
find /var/log -type f -mtime +90 -ls
123456 4 -rw-r--r-- 1 root root 4096 Jan 15 2023 /var/log/old_log.gz
123457 8 -rw-r--r-- 1 root root 8192 Dec 20 2022 /var/log/archived.log
The -ls action provides detailed listing of found files.
17. Find files modified in last week and copy to backup
find /home/user/documents -type f -mtime -7 -exec cp {} /backup/ \;
(No output if successful, files are copied)
Uses -exec to execute a command on each found file.
18. Find empty files modified in last 24 hours
find . -type f -empty -mtime 0
./temp_empty.txt
./logs/placeholder.log
Combines multiple conditions: regular files, empty, and modified today.
19. Find files modified between specific dates
find /data -type f -newermt "2024-01-01" ! -newermt "2024-01-31"
/data/january_report.pdf
/data/jan_data.csv
Uses -newermt to find files between two specific dates.
20. Find files accessed before specific time
find /home -type f -atime +60 -name "*.txt"
/home/user/old_notes.txt
/home/user/archive/readme.txt
Combines time-based search with filename pattern matching.