You can combine search criteria in the find command using logical operators. Here are the main operators you can use:
-
AND (
-aor simply by placing conditions next to each other): This operator allows you to specify that all conditions must be true for a file to be included in the results.find . -type f -name '*.txt' -size +1MThis command finds all regular files (
-type f) with a.txtextension that are larger than 1MB. -
OR (
-o): This operator allows you to specify that at least one of the conditions must be true.find . -type f -name '*.jpg' -o -name '*.png'This command finds all files that are either
.jpgor.png. -
NOT (
-notor!): This operator allows you to exclude files that meet a certain condition.find . -type f -not -name '*.log'This command finds all regular files that do not have a
.logextension.
Example of Combining Criteria
You can combine these operators to create more complex queries. For example:
find . -type f \( -name '*.txt' -o -name '*.md' \) -a -size +1M
This command finds all regular files that are either .txt or .md and are larger than 1MB. The parentheses \( and \) are used to group the conditions.
Note
When using logical operators, it's often a good practice to use parentheses to clarify the order of operations, especially when combining multiple conditions.
