find
find files by size
Find limit search depth
Find files older than X minutes
Find Inside File
1 |
find ./ -type f -name '*.*' -exec grep 'STRING_TO_FIND_HERE' {} \; -print |
Or
1 |
grep -rnw '/path/' -e "STRING_TO_FIND_HERE" |
-r = recursive
-n = show line number
-w = whole word only (you can omit this if you need partial match).
Files files changed in last 1 day
1 |
find /path -mtime -1 -ls |
-1 = changed in last 24 hours
+1 = changed earlier than 24 hours. Useful to find older files.
Delete files older than x days
To delete files older than 30 days, run
1 |
find /path/ -type f -mtime +30 -exec rm -f {} \; |
If you need to delete a partificular type of file, say .log files, use
1 |
find /path/ -type f -mtime +30 -name "*.log" -exec rm -f {} \; |
Instead of “-exec rm -f {} \;”, find support -delete option
1 |
find /path/ -type f -mtime +30 -name "*.log" -delete |