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 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.

Create an account

Register a new account

• Forum Statistics

• Total Topics
627759
• Total Posts
2978958

• 11
• 10
• 10
• 23
• 14