Image taken from:

ls *.c:


What happens when you use this command in a UNIX, UNIX- like shell?

Whether you are a master programmer, or a regular user of UNIX or UNIX-like operating systems, you will have come across the shell command ls.

What is ls?

According to the man page of ls (the manual of the command where his uses and options are listed), this command is used to list directory contents, but, what happens when you only want to list files with the extension .c?.

So, what does it mean to have a file with a .c extension?

First, you want to know that all the files with an extension .c corresponds to the code developed to run with the programming languages C or C + +.

Alright, but do you know what does the * has to see in all this?

The UNIX and UNIX-like OS shell allows you to make use of special characters called wildcards, which are characters that can represent a string of characters or an empty string, think of a joker in poker; there is one in particular that is perfect when looking for files with a certain extension: *.

This character matches any character or set of characters, including no character, which means that if this wildcard is used, it will refer to any character including rare characters such as &%$#”.

So…, answering the important question:

When you type that command in a shell like this: ls *.c and press enter, the shell will list all files ending in .c inside the current work directory, it looks like magic, but it is not, it is the awesome shell commands on UNIX and UNIX based systems.