What Does “ls *.c” Do in the Shell?

Your computer’s terminal is a command line interface where you can interact with your computer by typing commands, instead of moving your mouse and clicking on your screen as you would do in the graphical user interface used by the majority of computer users.

To actually make things happen in the command line interface, however, a program called the shell is used, which functions as a input box. Users type input into the shell through the keyboard and the shell passes the input in the form of a command to the computer, telling it what to do. The computer then executes the command. The shell programming language most commonly installed on Linux systems is called bash (Bourne Again SHell).

Commands can take arguments to refine your results. For example, the incredibly useful ls, entered alone, prints a list of all the contents of the current working directory (folder). If you want to list specific files and/or folders only, pass arguments to the command by typing them after ls. To execute the command, hit enter. Hitting enter after typing “ls *.c” in the shell will print a list of all files with a .c extension in the current working directory. The argument *.c is passed to ls, only showing all results that match.

“ls” alone list all the files in the folder, whereas “ls *.c” lists only the files ending in .c

As seen in the above image, the files “fun” and “shell” are not listed when you pass the *.c argument to the ls command. This is because * is a wildcard that represents any number of characters, and adding “.c” after * will tell the ls command to only list files that end in .c.

Like what you read? Give Allison Weiner a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.