Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've come to use the following command so often that I've written a script for it in my ~/bin - 'narrow':

    #!/bin/bash
    xargs -n 1 grep -l "$@"
This takes a list of files on stdin, then greps for the argument in all the files and spits out the matching files.

The perk is that it can be chained:

    find *.txt | narrow dog | narrow cat | narrow rabbit
This will find all the files that contain dog, cat, and rabbit.


But why run so many greps? I don't think there's a need for -n1 here.

    xargs -rd'\n' grep -l "$@"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: