What happens when you type `ls *.c

Example of ls *.c command being used with several directories and files ending in .c

The command ls *.c in a nutshell will list any file ending in .c that is in the current directory AND it will list the contents of any directory ending in “.c. Since the command is not recursive, meaning it will continue to follow every folder or directory down the chain until it ends, it will not list the contents of any further sub-directories.

Let’s now break the command step by step and piece by piece. The ls command will list the contents of the current directory. The symbol * is a wildcard looking for anything, and since .c is after anything * we are looking for any file ending with .c. So on the first pass, the command lists any files ending in .c in the currently directory, and after that it will list all the contents of any directory ending in .c, including files that do not end in .c.