How to combine multiple search conditions with the 'find' command in Linux?
Published on Aug. 22, 2023, 12:17 p.m.
To combine multiple search conditions with the ‘find’ command in Linux, you can use options like -name
, -size
, -type
, -newer
, etc. along with logical operators like -and
, -or
, and -not
. Here is an example command that uses multiple search conditions to find files modified within the last 7 days, smaller than 1 MB, and with the extension .log
:
find /path/to/directory -type f -name "*.log" -size -1M -newermt "-7 days"
This will find all files in the specified directory and its subdirectories that match all three conditions.
You can also use parentheses to group multiple conditions and specify the order of evaluation. For example:
find /path/to/directory -type f \( -name "*.log" -or -name "*.txt" \) -size +100k
This will find all .log
or .txt
files in the specified directory and its subdirectories that are larger than 100 kilobytes.
I hope this helps! Let me know if you have any other questions.