How to open multiple files from `find` output?

I know I can open multiple files found in a dir like so:

find -name *.foo -xargs <command> {} ;

This works, but when trying to open a bunch of textfiles in gedit at the same time, it opens them successively (when one files is closed, the next one is opened).

I would like to open all of those files at the same time.
How can I achieve this?

Asked By: jottr

||

I think that in this case you could use

find ./ -name *.foo | xargs gedit
Answered By: pbm

To act on multiple files at once with find, use + instead of ;:

find . -name '*.foo' -exec gedit {} +

With zsh, or with bash ≥4 if you put shopt -s globstar in your ~/.bashrc, you can use **/ to recurse into subdirectories:

gedit **/*.foo

Zsh also has many glob qualifiers which can replace most uses of find.

On Mac OS X bash you can run something like:

for file in $(find . -name "*.py"); do open -a SublimeText $file; done. 

One drawback is that it opens in new window of Sublime instead of using new tab.

Answered By: andilabs
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.