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
or
find . -perm -4000 -type f
find files and print only file name instead of full path – use formating with printf
find . -type f -printf '%f\n'
there are many formating options, just run man find and search -printf in there.
Note – always use single quotes around parenthesis when using -exec like so: -exec rm ‘{}’
find files and print out file size, permissions, owner ID and last modification time in seconds from unix epoch along with the files md5 hash
find . -mount -type f -printf "%k %U %m %T@ " -exec md5sum {} \;
-mount will not descend directories on other filesystems. Its useful if you have mounted other filesystems, especially network shares to the directory tree.
If you found this useful, say thanks, click on some banners or donate, I can always use some beer money.