3 ms·
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 tak
by sordina 14y ago
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.
- ralph 14y agoBut why run so many greps? I don't think there's a need for -n1 here. xargs -rd'\n' grep -l "$@"