joel silva
2 min readSep 15, 2020

What happens when you type ls *.c on shell?

ls command

If you need to list files that only have the .c extension you can use ls *.c to display a list of files ending with .c. But how does it work?

First of all, you need to know about the ls command. The ls command is used to make a “list”. For example, if you are in the / home directory you can use the ls command to see the files and folders in this space.

this image shows the result of ls

with ls -1 we can make the list look in a more orderly way. in this way we can see it like this

this image shows the result of ls -1

Now we have the * character after ls command, this character is known as a Wildcard and it’s represented by an asterisk (*). The wildcard help us find certain characters, or files that can be letters, file extensions, etc. To simplify the use of this character we can see a few examples of it.

this table shows examples of characters

If the wildcard (*) is before the character or pattern means that all the files starting with that character will be displayed as a result. If the wildcard (*) is after the character it means that the file ending with that character will be displayed.

Finally, we have the .c which means the file extension or the patter that the command ls will try to find. So, the command ls will display all files ending with .c extension. This is the final result

this is the output of ls * .c

joel silva
joel silva

No responses yet