View Single Post
Posts: 3,617 | Thanked: 2,412 times | Joined on Nov 2009 @ Cambridge, UK
#18
Originally Posted by jukzh View Post
Note, it's not exactly the same thing.
Code:
/home/user # time find . -name "*.py" | wc
real	0m 0.63s
user	0m 0.11s
sys	0m 0.46s
       95        95      5352
/home/user # time find . | grep "*.py" | wc 
real	0m 0.87s
user	0m 0.12sa
sys	0m 0.45s
        0         0         0
/home/user #
The find on it's own is obviously more efficient, which is why the times are lower. You don't want to use "*.py" in the grep though, as grep uses regular expressions and not globbing, so "\.py$" will get you the same results (the "\" is needed to escape the ".", which represents a single-character wildcard, and the "$" is needed to anchor the search to the end of the name, otherwise any ".py" in the middle of names will be picked up as well).