3 ms·
Good point! But sometimes a large-scale parallel filesystem can't beat a local SSD on certain patterns. Also, we didn't see any timings for that 1,000x claim,
by kilianc 7y ago
Good point! But sometimes a large-scale parallel filesystem can't beat a local SSD on certain patterns.
Also, we didn't see any timings for that 1,000x claim, so let's say it's an estimate. :)
- emmelaich 7y agoIt's a great article, thanks. But .. do people actually use `ls` to list so many files? I mean, it'd scroll off the terminal anyway.
- chris_wot 7y agoI admit to being guilty of the odd for i in $(ls) do Something dumb done
- myrandomcomment 7y agoIt is like you read my script.sh over my shoulder as I was writing it. :)
- zaphirplane 7y agoOut it interest why not xarg or find’s exec
- freedomben 7y agoNot GP, but I often find myself writing making statements (which is awkward with find), or using syntax that find struggles with.
- xorcist 7y agoIt clearly depends on what good that subshell running ls does for you, but the trivial form would be: 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.
- wahern 7y agofor 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.
- mirimir 7y agoI sometimes ls | grep.
- CaliforniaKarl 7y agoSo, I need to call out one thing. For the people mentioning `ls | grep` and the like, in auto mode `ls` disables colors when it sees it is not running in a terminal. So using it in a shell script (or similar construction) doesn’t have this issue. Otherwise your loop variable would be full of weird ANSI escape color sequences!
- CaliforniaKarl 7y agoYup, some people do. Maybe they don’t expect so many files. Maybe they are gonna scroll around. But they do.