Leopoldo Luna
1 min readSep 15, 2020

--

What happens when you type ls *.c

What happens when you type ls *.c?

The ls command tells the program to list all files and directories in the current working directory. In this input however, there is a wildcard that is implemented before the ‘.c’. The wildcard is symbolized by the asterisk. The asterisk wildcard matches the characters that are placed after it, and tells the program to look for files that match those same characters. When one places an asterisk before ‘.c’ like in this example, you are telling the program to only list files that end with a ‘.c’.

The wildcard can be used in different circumstances as well. Let’s say you want to write a program that lists all the files that only start with the letter ’n’. In this case, all one has to do is place the asterisk after the character that you want it to match. So it would look like ls n. Wildcards can also be used to match an entire spectrum of characters, or certain type of characters. To write a program that starts with a,b, or c, you can write [abc]. Or, if you want to write a program that ends only with a capital letter, the input would be *[[:upper:]].

There are many more ways to implement this expansion, but I hope you learned something about ls *.c.

--

--