Thursday, January 2, 2020

find : useful syntax not regular

Find files with permission 777 (change value as per the search), for dir use type as d
find . type f -perm 0777 -print

Find and correct the permission:
find . -type f -perm 0777 -print -exec chmod 644 {} \;

Find and remove files
find . -type f -name *.javacore -print -exec rm -f {} \;

Find empty files
find /tmp -type f -empty

Find hidden file
find /home type f -name ".*"

Find last 50 days accessed files:
find / -atime 50

Find changed files in last 1 hour:
find / -cmin -60

Find modified files in 60 min:
find / -mmin 60

Find files modified in last 50 days
find / -mtime 50

Find files accessed in last 1 hour:
find / -amin 60

Find 50MB File:
find / -size 50M

Find size 50 - 100 MB:
find / -size +50 -size -100M


Find and delete 100 MB and bigger files:
find / -size +100M -exec rm -f {} \;

Find the files greater than 1 MB and do proper listing
find /home -size +1M -exec ls -lrt {} \;


Find specific type of files and delete

find / -type f -name "*.mp3" -size +10M -exec rm {} \;

No comments: