1. Find all the files with respect to their permission
using octal method
# find / -perm 755 -type f
using symbolic method
# find / -perm u=rwx,g=rx,o=rx -type f
Find all files with executable permission
# find / -executable -type f
Find all files with writable permission
# find / -writable -type f
Find all files with readable permission
# find / -readable -type f
2. Locate files with respect to their special permission
Find all the executable files inside /usr/bin, /bin/, /usr/sbin/, /sbin/ with SGID
# find /usr/bin/ /bin/ /usr/sbin/ /sbin/ -perm +2000 -execuatble
/usr/bin/ssh-agent
/usr/bin/locate
/usr/bin/wall
/usr/bin/write
Find all the executable files inside /usr/bin, /bin/, /usr/sbin/, /sbin/ with SUID
# find /usr/bin/ /bin/ /usr/sbin/ /sbin/ -perm +4000 -execuatble
/usr/bin/ksu
/usr/bin/gpasswd
/usr/bin/chsh
/usr/bin/chage
/usr/bin/sudo
3. Locate files with respect to size
Find all the files with more than 30MB size
# find / -size +30M -type f
Find all the files with more than 1GB size
# find / -size +1G -type f
Find all the files with more than 6KB size
# find / -size +6k -type f
NOTE: In case you want to find files/directories with size less than, use "-" sign instead of "+" sign in above examples
4. Find files with respect to their owners
Find all the files whose user owner is deepak
# find / -user deepak -type f
Find all the files whose group owner is deepak
# find / -group deepak -type f
NOTE: You can also use -uid and -gid argument respectively instead of -user and -group
5. Saving o/p to file with extra parameter
This command will locate for all the files/directories with user owner deepak and save the o/p to file.txt (the o/p will resemble same as ls -l)
NOTE: If the files does not exist it will be created, and if it already exists then it will be overwritten
This command will just save the o/p to file.txt
# find / -user deepak -fprint file.txt
# cat file.txt
/home/deepak
/home/deepak/.bash_profile
/home/deepak/.bashrc
/home/deepak/mywork
/home/deepak/.bash_history
/home/deepak/work
/home/deepak/.gnome2
/home/deepak/.mozilla
6. Add an extra argument along with find command
This command will show you long list details of all the files with size more than 50MB
7. Find files irrespective of case
This command will find all the files/directories inside /home with name "test" irrespective of case
# find /home/ -iname test
/home/deepak/test
/home/deepak/Test
8. Find files/directory with respect to their name
Find all the files/directories with name "test"
# find /home/ -name test
/home/deepak/test
9. Find files using wildcard
This command will search all the files with .txt extentsion
# find / -name *.txt -type f
This command will search all the files from file[0-9] with .txt extentsion
# find / -name file?.txt -type f
10. Find files with respect to their modification/access time
Find all the directories accessed before 5 min
# find / -amin -5 -type d
Find all the directories accessed 60 min back from current time
# find / -amin +60 -type d
Find all the files/directories accessed exactly 5 min back
# find / -amin 5 -type d
Find all the files/directories accessed 5 days back
# find / -atime -5 -type d
NOTE: You can run all the above commands as per the modification time just by replacing "-atime" with "-mtime"
Complex example
Locate all files with name test.tx inside /home/deepak and remove them
# find /home/deepak/ -name test.txt -type f | xargs rm -f
or
# find /home/deepak/ -name test.txt -type f -exec rm -f {} ;
Please do let me know your feedback or in case I missed any thing.
Related Articles
8 examples to help you understand top command usage in Unix/Linux
7 Commands to read or view the contents of a file using CLI in Linux