3 ms·
Protip: if you just want to see what files are there use "echo *", it's much faster than ls.
by lmm 11y ago
Protip: if you just want to see what files are there use "echo *", it's much faster than ls.
- MichaelBurge 11y agoIt might be faster, but it won't work for large directories. For large directories, I either use 'ls --color=never' or the example C program in 'man 2 getdents'.
- gnosek 11y agols -U avoids the default sort by name. Without -U you get all the names at once at the end of the directory scan. With the option you get them one by one (in some unspecified order) and can make sort of a progress bar for counting files in large directories: ls -U huge_dir | awk 'NR % 100000 == 0 { print NR } END { print NR }' (prints the count every 100k files and the total at the end).
- sua_mae 11y ago/bin/ls do the trick to avoid all options on the alias.
- tyingq 11y agoTested a few things. "ls -U" seems to be the fastest approach I could find. -U disables sorting. $ mkdir testdir && cd testdir # make 200k files $ perl -e 'for (1..200000) {open(FOO,">$_");close(FOO)}' $ time echo * >>/dev/null real 0m1.607s user 0m1.480s sys 0m0.128s $ time ls >> /dev/null real 0m1.458s user 0m1.324s sys 0m0.132s $ # globs $ time perl -e 'for (glob("*")) {print "$_\n"}' >>/dev/null real 0m0.679s user 0m0.404s sys 0m0.272s $ time find . -maxdepth 1 -print >> /dev/null real 0m0.239s user 0m0.128s sys 0m0.108s $ time ls -U >> /dev/null real 0m0.195s user 0m0.064s sys 0m0.132s