For example, if you are in home directory and type ls *, you will have all the directories listed, and below the name of the listed directory, the files that it contains. On the other hand, if you type echo * the command will list just the directories, and not the directories and content that they have. Why is that?

  • 5
    because echo and ls are not the same. – αғsнιη Feb 20 '15 at 19:36

In both cases the * gets expanded by the shell.

echo than just prints the parameters resulting from the expansion.

ls checks for every parameter if it is a directory and lists its contents if it is one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.