Sign in to follow this  
matrisking

RANDOM shell scripting question

Recommended Posts

I'm not sure if this is the appropriate place to ask this question, but here I go... In unix shell scripting, I just noticed that if I enter "ls" in a directory containing 28000+ files it takes a LONG time for the output to appear. However, if I do something like this: > ls | grep "" It happens almost instantly. Same goes for something like this: > echo `ls` (note the grave accents). Can anyone explain why these 2 methods are so much faster that a simple "ls"? Thanks in advance.

Share this post


Link to post
Share on other sites
Not knowing what ls implementation and what shell you are using, I'd have to guess that the slow down when you are using ls by itself is that the shell the time to read in the entire directory contents and the formats the output by column. When ls is piped to another application it just writes as fast as it reads the entries.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this