ls *.c explained

Ashley Price
2 min readSep 15, 2020

--

When you’re working in the shell, there are several different ways to get information. Depending on what you’re looking for, there is bound to be a shortcut.

ls

ls will show the files and folders in the current working directory. By looking at the man page for ls you can see there are many different ways to further refine that data.

ls *.c

So we know that ls will display the files and folders in your current working directory. * serves as a wildcard, so when combined with .c it is telling the system to only show you files ending in the .c extensions.

If we want to break it down further, there is even more information we can get from this.

First it reads ls and checks for any existing aliases. An alias is a command which enables the replacement of a string. When it does not find an alias, it moves on to our wildcard, *. With the * character, it triggers shell expansion. This means the * expands into larger text, files, or other general output. You can write a string before or after the *. Here, the * is going to locate any files ending in .c.

When the command is executed, the shell will search for the command in existing build-ins. Then it will find $PATH, an environmental variable specifying where the executable programs are located. When it is found the shell will execute the command. In this example ls will be locating all files ending in .c.

After the command is executed, it exits the command and displays the prompt once again.

--

--