find

The following command finds files or directories modified in the last 10 minutes and asks before deleting each one.

find . -mmin -10 -ok rm -rf {} \;

Explanation

In plain English: find all files and folders changed in the last 10 minutes, and ask before deleting each one.

Other useful find usages

1. Find files modified within the last day

find . -type f -mtime -1

2. Delete empty directories

find . -type d -empty -delete

3. Find large files (>100 MB)

find . -type f -size +100M -exec ls -lh {} +

4. Find all .log files modified in the last hour

find /var/log -name "*.log" -mmin -60

5. Find files with insecure permissions (writable by others)

find . -type f -perm /o+w

6. Find and delete .tmp files older than 7 days

find /tmp -name "*.tmp" -type f -mtime +7 -delete

7. Find files containing a specific word

find . -type f -name "*.cpp" -exec grep -H "TODO" {} +

8. Find all symbolic links pointing to missing files

find . -xtype l

9. Find files owned by a specific user

find /home -user ccn

10. Find files newer than a reference file

find . -newer reference_file.txt

edit this page