How to use the ls *.c command on Linux?
The ls command is one of the most useful and basic commands in Unix-like operating systems and is used to list the names of the files and directories inside a specific folder. Next is the structure of the ls command.
Command Structure:
ls [option] [file]
This time we are going to be focused in the use of ls command along with a wildcard on the next form: ls *.c
However, before going any further on this topic we should make clear that a wildcard is a character that matches or expand specific types of patterns in order to make efficient searches through the file system. For the command we are applying, we use the character '*' known as the star character that can match any string of any length.
Summing up the last definitions we have that ls *.c will list all the files and folders that end with a .c and to have a better understanding of each one of this parts we are going to make a step-by-step guide as shown below:
- First, we use ls command alone, and as we saw before the command lists the files and directories in the current working directory.
- Then we are going to add the star character '*' after the ls command with the intention to list the files and folders, but also the files inside the subdirectories of the current working directory.
- Finally we add the .c along the '*' character in order to match all the files and folders ending with a .c