Quantcast
Channel: Count number of files that are not symbolic links in output from "locate" - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 5

Answer by Ole Tange for Count number of files that are not symbolic links in output from "locate"

$
0
0

With GNU Parallel it looks like this:

locate -r "$PWD.*\.c$" | parallel 'test -f {} && echo "regular file"' | wc -l

As you can see it is extremely close to your initial attempt.

If you have fewer than 100 hits, you can use that GNU Parallel sets $? to the number of failed jobs up to 100 (THIS DOES NOT SCALE):

ls  *txt | parallel \! test -f {}echo $?

If you need it even faster:

locate -r "$PWD.*\.c$" |  perl -ne 'chomp; -l $_ or $s+= -f $_; END{print "$s\n"}'

Or the combination:

locate -r "$PWD.*\.c$" |  parallel --block 10k --pipe -q perl -ne 'chomp; -l $_ or $s+= -f $_; END{print "$s\n"}' |  awk '{s+=$1} END {print s}'

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>