7

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.

2
  • 3
    Next time you should try to read man YOURCOMMAND (in this case find) first. Apr 23, 2012 at 8:25
  • @PaulR: If you don't use regexexs, maybe, but both, find and locate, can handle regex, and therefore it can be alright here, imho. Apr 23, 2012 at 21:58

3 Answers 3

10
 find -name "*.jpg" -o -name "*.css"
1
  • This ./ seems a bit unnecessary here?
    – Bernhard
    Apr 24, 2012 at 20:46
5

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"
1
  • 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
2

Alternatively, you can type :

find -name "*.jpg" -or -name "*.css" 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .