find Linux command tricks asked in exams and how to write

find Linux command tricks asked in exams and how to write

======================

A

The find Operators (!, -o, and -a)
There are three operators that are commonly used with find. The ! operator is used
before an option to negate its meaning. So,

find . ! -name "*.c" -print

selects all but the C program files.
B
To look for both shell and perl scripts, use the -o operator, which represents an OR condition. 
We need to use an escaped pair of parentheses here:
find /home \( -name "*.sh" -o -name "*.pl" \) -print

The ( and ) are special characters that are interpreted by the shell to run commands in
a group. The same characters are used by find to group expressions using the
-o and -a operators, the reason why they need to be escaped.
C
Also to find all *.sh (shell scripts) files for user tux execute:
find /home -user "tux" -name "*.sh" -print 
find /home -user "tux" -name "*.sh" -exec ls {} >| file.txt \; # write listing in file.txt 

these two commands  are equivalent to these two >>>

find /home \( -user "tux" -a -name "*.sh" \) -print
find /home \( -user "tux" -a -name "*.sh" \) -exec ls {} >| file.txt \; # write listing in file.txt 

I conclude in some commands use find for finding:

Directories with sticky bit set:
find / -type d -perm -1000 -exec ls -ld {} \;

Files with SGID set:
find / -type f -perm -2000 -exec ls -l {} \;

Files with SUID set:
find / -type f -perm -4000 -exec ls -l {} \;

Files with SUID and SGID set:
find / -type f \( -perm -4000 -a -perm -2000 \) -exec ls -l {} \;

Files with SUID or SGID set:
find / -type f \( -perm -4000 -o -perm -2000 \) -exec ls -l {} \;








































Note:
ALL THESE COMMANDS - IF NOT WORK - MAKE THE APPROPRIATE SPACING eg  \( -user "tux" like exactly I write

Further Reading Resources

https://likegeeks.com/linux-command-line-tricks/