- Don't parse
ls
. It's output is not reliable and it's only made to look at (for human parsing). See http://mywiki.wooledge.org/ParsingLs.
- Don't use
xargs
. It mangles your data trying to be smarter. Got spaces or quotes in your filenames? You can be sure that it'll explode.
To make xargs
behave, you'd have to go to great lengths:
printf '%s\0' *Exam* | xargs -0 open
Yes, that's rather convoluted. Read on.
The find
solution, while accurate, is recursive (might be what you want), but also a bit much to type in a prompt.
find . -name '*Exam*' -exec open {} +
You can make all that a lot easier by remembering that open
on Mac OS X takes multiple arguments just fine (which is exactly what xargs
does), so this is just fine for opening all documents in the current directory that contain the word Exam
:
open *Exam*