"he mentioned his laptop was 1,000x faster than Sherlock to list this directory’s contents"
"that’s a 40x speedup right there"
So... what about... the rest?
"that’s a 40x speedup right there"
So... what about... the rest?
Also, we didn't see any timings for that 1,000x claim, so let's say it's an estimate. :)
But .. do people actually use `ls` to list so many files? I mean, it'd scroll off the terminal anyway.
for i in $(ls)
do
Something dumb
done for i in *txt
do
...
done
The reason to stuff every file name through ls (keep in mind that it's always your shell doing glob expansions, ls is not involved) would be to sort them by creation date or some other processing that ls can do. But as soon as there are many files involved, or those sorting arguments gets non-trivial, it will fall apart completely.Use find | while read instead, or xargs. That's going to be easier on the eyes and actually work.
for i in *; do
...;
done
works even better as it can handle files with whitespace. I usually disable file globbing but enable it specifically for code like this.EDIT: Actually, one issue with the above is that if there aren't any matching files then you get a literal "*". But I'd rather deal with that then break when filenames have embedded whitespace.