ls returning contents of current directory and sub-directories

What happens when you type ls *.c

Among the many shell commands at your disposal, ls remains among the most heavily used commands in shell. When you type man ls and hit enter, the manual page for the command ls appears, and it is here where you can learn all about the command.

Manual page for the command ls

From the description we know that ls displays information about the files in a certain directory (current directory by default).

ls without arguments

To refine the results we want ls to return, we may add arguments after ls (eg. ls *.c). In the case of ls *.c, ls is the command, and *.c is the argument. Asterisk (*) is known as a wildcard; when an argument contains this wildcard it causes shell to perform pathname expansion. In the case of the asterisk wildcard, it expands into any possible combination of characters with varying length, causing * to stand for anything. This leads to the case of ls *.c where we want ls to print information on files beginning with anything ,but ending with .c.

ls with *.c as agruments

Compared to the results of ls without arguments, ls *.c only returned files ending with .c.

Like what you read? Give Teng Alex Yu a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.