5 ms·
The thing that I use find for most commonly is to perform a hierarchical grep, i.e find . -exec grep -Hn regex \{\} \; How would you do that with the du | gre
by amoss 3y ago
The thing that I use find for most commonly is to perform a hierarchical grep, i.e
find . -exec grep -Hn regex \{\} \;
How would you do that with the du | grep combo?
- geosh 3y ago... | xargs grep -Hn regex This will also be faster, because you fork less.
- ykonstant 3y agoDoes this deal with arbitrary filenames (having newlines, control chars etc) correctly? Or does Plan9 forbid such filenames?
- geosh 3y agoI've never used plan9. In Linux you do "find -print0 | xargs -0" to deal with that. Im not sure how one can do \0 separator with du, plan9's du(1) doesn't list such option.
- arp242 3y agoUsing \+ instead of \; will do the same (fork less). du -a will need to do a stat to get the file size, which is comparatively expensive; I don't think find will (not sure)?
- jlokier 3y agoYou're right, find won't call stat() unless it needs to. It doesn't need to for recursing through the directory tree because readdir() returns dirent.d_type these days to determine if a name is a directory. Yes, those stat() calls can be very slow in aggregate on a large tree, especially from HDD (due to seeking) or network filesystem, if the stat information isn't already in cache.
- geosh 3y agoOh, I forgot about \+. I still pipe to xargs every single time.
- somat 3y agogrep -R
- amoss 3y agobut old habits die hard :)