A faster ls

echo *
Sometimes "ls" is just too slow, especially if you're having problems with terminal scroll speed, or if you're a speed freak. In these situations, do an echo * in the current directory to immediately see the directory listing. Do an echo * | tr ' ' '\n' if you want a column. Do an alias ls='echo *' if you want to achieve higher echelons of speed and wonder. Note that echo * is also useful on systems that are so low in memory that "ls" itself is failing - perhaps due to a memory leak that you're trying to debug.

By: kFiddle
2009-04-17 21:40:58

What Others Think

Yes, it'll print all filenames quite fast, all in one line, and the use of tr(1) won't work if there's (ugh) spaces in filenames. Also, mapping ls to "echo *" is not a good idea at all. Too many scripts depend on such a vital command as ls(1) and will break in some way or another. Things stored in /bin/ are essential on a *NIX system and should not be tampered with.
sunny32768 · 652 weeks and 6 days ago
This might get you out of a scrape in rare circumstances.. but don't alias it! In addition to the previous posters comments, this *will* fail on directories that contain many files as the wildcard will expand beyond the size of the shell parser's command line buffer.
animoid · 652 weeks and 6 days ago
Too much typing, and what are you gaining really? Is your hardware that slow that you notice the difference?
atoponce · 652 weeks and 5 days ago
Here's what you gain: ls real 0m0.007s user 0m0.000s sys 0m0.008s echo * real 0m0.002s user 0m0.000s sys 0m0.004s echo * | tr ' ' '\n' real 0m0.008s user 0m0.004s sys 0m0.004s I don't notice it much...
brie · 609 weeks and 6 days ago
Timings using an Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz - Ubuntu 9.10 Karmic 64bit using bash in gnome-terminal: ls /usr/lib/ real 0m0.563s user 0m0.030s sys 0m0.010s echo /usr/lib/* real 0m0.086s user 0m0.020s sys 0m0.000s using bash on first console (the infamous Ctrl+F1) ls provide 0.25s echo provide 0.024s seems that "ls" output time is about 6 times "echo" output time To me prove that echo is faster than ls in pseudo-pure computational time (in bash on gnome-terminal)...better values on first console (echo is 10 times faster than ls) I disagree totally about aliasing ls due to it's own obvious conclusion in terms of pipings issues. I found this solution very interesting when I have to simply parse folder content in term of pure strings.
LucaCappelletti · 609 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: