Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer

I think that in this case you could use

find ./ -name \*.foo | xargs gedit
share|improve this answer
1  
This won't work if the file name contains special characters (whitespace or \'"), because xargs requires its input to be quoted in a way that find doesn't produce. Either use find … -print0 | xargs -0 …, or use the simpler find … -exec … {} +. – Gilles Nov 28 '10 at 15:34
Also, though it doesn't apply in this case, -print0 | xargs -0 has the problem that stdin has been gobbled up, and is no longer attached to the terminal. A problem if you're trying to use a text-mode editor. – derobert Dec 14 '12 at 16:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.