The power of the linux ‘ls’ command
There are many commands for the Linux operating system, however, we will explain on this occasion how important it is to know how to use the “ls” command. Typing this command in our terminal helps us to list the contents of the directory we are referring to, as shown below:
As you can see, when typing the command “ls” the output is all the files that are in the directory called “command” (blue), whose files with their respective extensions are: code.c command.txt hello.html hello_world.c main.js programming.c style.css style.js.
Now, what if you only want to see one file extension? For example, we only want to see the extension ending in .c, so we do the following:
What happened when you typed in *.c? The first part of the script is ls, as we have seen, lists all the contents of the directory we are. The second part is “*”, the character “*” is a wildcard that refers to the name or extension of a file, as the case may be. The wildcard “*” helps us to find all the possible combinations coming from the files in the directory we are referring to.
And finally, the third part of the script is “*.c”, with this, we are referring to make the list of the files that have the extension .c, for our case are the files: code.c hello_world.c programming.c
For example if you only want to see the list of files whose extension .c and .html is used the script ls *.c *.html, as shown below:
It is important to note that the command ‘ls’ has more uses, in this post we only wanted to emphasize how it can be used with the wildcard ‘*’ to list files with specific extensions.
REFERENCES