This version of the site is now archived. See the next iteration at v4.chriskrycho.com.
Topic: “editor”

Launch an editor with a list of files containing a string

This one’s here for my own reference as much as anything, because I will want to do this again and I’d rather not have to go dig it up.

If you want to launch an editor with a list of files matching a specific pattern from any Unix or Linux terminal, the quickest and simplest way I’ve found to do it as follows:

find directory [-name modifiers] -exec grep -l pattern | xargs editor

So, for example, I just wanted to use Sublime Text 2 open every Fortran 95 file in a directory that writes to disk, so I ran the following:

find . -name "*.f95" -exec grep -l 'write(' {} + | xargs subl

Read on, intrepid explorer →