This might be quicker for the inner part:
Code: Select all
find /usr -type f \( -name "*.la" -o -name "*.pc" -o -name "*-config" -o -name "*.pm" \) -exec grep -qF png14 {} \; -exec qfile -CSq {} + | uniq
This is POSIX compatible; + has been around for ages[1], although GNU find was scandalously late in implementing it a few years ago, and takes the place of a similar xargs construct which might be more familiar:
Code: Select all
find /usr -type f \( -name "*.la" -o -name "*.pc" -o -name "*-config" -o -name "*.pm" \) -exec grep -qF png14 {} \; -print0 | xargs -0 qfile -CSq | uniq
Here the thing to realise is that the next action is taken if the previous one was true (implicit AND); that's why you have to parenthesize off the -o/OR'ed part. This works with an -exec as well; using grep -q simply to give an exit status for the match (and of course -F as it's a fixed-string) means we can check the file once and then do something else with it; printing it through the pipe like this means we don't have to cut the file names and then pass a whole bunch of duplicates to qfile. Of course, we can also use a further action, which gives the example at the start; there the + simply collects arguments until it has enough to fill a command-line (or has run out.)
-print0 has also been around for ages, but is not specified in POSIX, though it is discussed in links below.
There's no point using
sort | uniq ime; if you really want that use
sort -u. (If I'm missing something, let me know:) Here of course it makes no difference whether the atoms are sorted; portage will work out a build-plan for all of them (mostly) irrespective of order on command-line. (Sorting by name doesn't help anything.)
I'm crashing out now, but bonus points for excluding
/usr/src and
/usr/portage ;)
HTH,
igli.
[1]
POSIX 04 find
[2]
POSIX 08 find
[3]
Classic find page from the best BASH website out there.
[4]
Start here for portable scripting; even if you're using BASH (and why not? It
is pretty portable ;) it helps to stick to portable commands and options where possible. GNU awk is nice; so if a script uses a GNUism, I use
gawk and not
awk as the command name, so it at least has a chance of running on other systems.