Skip to main content
12 events
when toggle format what by license comment
Dec 13, 2016 at 11:55 history edited Stéphane Chazelas CC BY-SA 3.0
edited body
Dec 13, 2016 at 11:53 comment added Stéphane Chazelas @Andrey, zgrep is a generally a script that calls gzip and grep for each file anyway.
Dec 13, 2016 at 11:01 comment added Andrey Yes, I know, maybe it's just for my application I can ignore such errors. As a side note, -r is not supported by some implementations of zgrep, so only find-based solutions would work for compressed files.
Dec 13, 2016 at 10:37 comment added Stéphane Chazelas @Andrey, 2> /dev/null would remove every error by grep and xargs, not just the terminated by signal 13 error by xargs.
Dec 13, 2016 at 10:35 history edited Stéphane Chazelas CC BY-SA 3.0
added 506 characters in body
Dec 13, 2016 at 10:25 comment added Stéphane Chazelas @V13, also calling one grep for each file won't stop find finding extra files. A pipe (in a find | xargs -n 1 approach) can hold thousands of files before getting full and causing find to block.
Dec 13, 2016 at 10:11 comment added Stéphane Chazelas @V13, you want to pass as many files to grep as possible, to run as few grep instances as possible. executing grep (which implies forking a process, loading the executables and libraries, do dynamic linking, initialise all libraries, internationalisation... and all the clean-up afterwards) has a formidable cost compared to find finding the files. With --line-buffered, grep should be killed early, so should not examine too many extra files once it has found 5 matching files.
Dec 13, 2016 at 9:15 comment added V13 The second approach may examine 100s or 1000s of files even though you're only interested in a couple because you are not limiting the lines that xargs will pass to grep. It also doesn't mask the SIGPIPE. Have a look at my suggestion.
Dec 12, 2016 at 20:13 vote accept Andrey
Dec 12, 2016 at 20:07 comment added Andrey Thank you. I will use grep -r for this particular task, but it's good to know how to solve a general case. One note: xargs still prints error xargs: grep: terminated by signal 13, while find stops. I'd add 2> /dev/null here.
Dec 12, 2016 at 17:43 history edited Stéphane Chazelas CC BY-SA 3.0
added 511 characters in body
Dec 12, 2016 at 17:15 history answered Stéphane Chazelas CC BY-SA 3.0