find files by size
Find limit search depth
Find files older than X minutes
Find Inside File
find ./ -type f -name '*.*' -exec grep 'STRING_TO_FIND_HERE' {} \; -print
Or
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 a partial match).
grep -irl "STRING_TO_FIND_HERE"
Files changed in the last 1 day
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
find /path/ -type f -mtime +30 -exec rm -f {} \;
If you need to delete a particular type of file, say .log files, use
find /path/ -type f -mtime +30 -name "*.log" -exec rm -f {} \;
Instead of “-exec rm -f {} \;”, find support -delete option
find /path/ -type f -mtime +30 -name "*.log" -delete
Leave a Reply