I am searching for files in linux and am able to execute the command to search for a single type of format e.g *.jpg
but would like to find all files with *.jpg
and *.css
in one command.
3 Answers
find -name "*.jpg" -o -name "*.css"
There is a fingerbreaking variant with regex:
find -regex ".*\.\(css\|jpg\)"
It's shorter and avoid pitfalls, combined with the -o versions:
find ./ -name "*.jpg" -o -name "*.css" -ls
The ls is only adapted to the second pattern, here. You can avoid it with
find ./ \( -name "*.jpg" -o -name "*.css" \) -ls
but that is getting a bit cryptic too.
Very fast for searching your whole system in the update-db-index is locate, which knows regex too, but doesn't find ultra fresh files:
locate -r "Frame.\(scal\|jav\)a"
-
Test it! In my machine the option without the brackets does not work - no errors are reported, but still only the last file pattern is applied. Oct 27, 2020 at 17:55
man YOURCOMMAND
(in this casefind
) first.