What happens when you type ls *.c into the shell

Photo by Markus Winkler on Unsplash

The shell

The commands passed can be of different types, which are:

  • An executable program: which is usually wrote in C, C++, Python, Perl etc.
  • A built-in command: this commands are proper programs of the shell as for example our ls command.
  • A shell function: little programs executing dedicated task.
  • An alias: This commands are allowed to be named and usually contains a group of other commands to execute a task, this alias helps to save time and typing for repetitive task that involves invoking several number on the terminal shell.

How commands are built

ls [option] [file]

The options are modificators that gives us different behaviors for the command, and the file is where we want to execute the action. The ls command executes a listing of the files and directories on the selected path and with the different option we can show this results in different ways for example long format listing or short format listing, all the options are listed on the manual page.

Wildcards

but for now we are going to focus on our (*) wildcard. This special character that matches one or more characters of a file name.

What the command ls *.c performs

This is our original list on the directory,

After we execute the listing command with the wildcard there is a filter of the documents according to our pattern, we show the result in the following image

So as we saw wildcards allow to filter our files to perform on them different tasks. This is a great tool that will allow you to save time and headaches.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store