find

Find files and folders and optionally do something with them

Find how many files with specific user/group ownership and permissions are in current directory and subfolders:

find . -user USERNAME -group GROUPNAME -perm 644 |wc -l

Find FILES with specific permissions in current directory and subfolders:

find . -type f -perm 640

Change file owner and group for files/directories which group membership is oldgroup

find . -group oldgroup -exec chown newuser:newgroup '{}' \;

Find and delete files/directories which are over 62 days old

find . -mtime +62 -exec rm '{}' \; > /dev/null 2>&1 

Find and delete files not having .gz extension

find /foo/ -type f ! -name "*.gz" -exec rm -f '{}' \;

Find files with SUID bit

find . -perm -4000

 

Note – always use single quotes around parenthesis when using -exec like so: -exec rm ‘{}’

If you found this useful, say thanks, click on some banners or donate, I can always use some beer money.

Leave a Reply

Your email address will not be published. Required fields are marked *