What happens when you type ls *.c in your shell ?

Redondo--Tanis Melvin
3 min readJun 16, 2024

--

ls *.c command in a zsh terminal and the result : 666.c betty.c main.c

History

The “ls” command, abbreviation of “list”, allows you to list the contents of a directory, appeared in Multics, the ancestor of Unix, in which it will be preserved, with the years options like “-l” and many others will be added, other implementations will emerge with BSD or even GNU.

Ken Thompson and Dennis Ritchie, working on PDP-11 and UNIX in 1972

Usage

By default the command will give you a simple list of your files and folders.

ls command in a zsh terminal and the result : addresses.txt cat_videos incredible_vacation_in_saint_denis thermonuclear_bomb_recipe.txt

By adding the following parameters you can list the contents of the directory with more information such as file and folder permissions, groups, creation date, size, etc…

You can also add the following settings to list and display hidden files and folders.

ls *.c ?

This is all very nice, but what does this famous command do?

The following syntax allows you to display all files ending with a “.c”, often on the command line the star means “all”

Ok but that’s not enough I need to understand how my computer does it, is it black magic? homeopathy?

When you type the ls *.c command in a terminal, the shell first interprets the *.c pattern by searching for all files in the current directory whose names end in .c. This step, called pattern expansion, transforms the command into an explicit list of files, e.g. ls file1.c file2.c file3.c. Next, the ls program is executed with this list of files as arguments. c file2.c file3.c. Next, the ls program is executed with this list of files as arguments. ls reads the necessary information on each of these files, such as their name, size, permissions and modification date, then displays them in formatted form in the terminal. This gives you a clear view of the C source files in the directory.

--

--

Redondo--Tanis Melvin
0 Followers

🌟 Hello, I'm a young developer passionate about exploring the depths of computer science through insightful articles.