A
A
Anatoly2019-06-03 04:21:53
bash
Anatoly, 2019-06-03 04:21:53

How to list files with FIND command?

Task: output files with jpg and png extensions, but exclude edit and 200x200 in the path/name to the file.
If you don't use extensions, then it works:
$find /var/www/test -type f ! -regex ".*\(edit\|200x200\).*"
If you don't use a regular expression,
$find /var/www/test -type f works! -name "*.jpg" -o -name "*.png"
If we combine reget and the name pair, then the output is not correct:
$find /var/www/test -type f ! -regex ".*\(edit\|200x200\).*" -name "*.jpg" -o -name "*.png"
What to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2019-06-03
@Tolly

$find /var/www/test -type f ! -regex ".*\(edit\|200x200\).*" -name "*.jpg" -o -name "*.png"

The operations in the find condition line have precedence, precedence of "or" is lower than precedence of "and". You get "(type is file, and not *edit* or *200x200*, and *.jpg) or *.png".
Add brackets:
If you do not use a regular expression, then it works:
$find /var/www/test -type f ! -name "*.jpg" -o -name "*.png"

...but not quite the way it should.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question