Sign in
Log inSign up
What Happens When You Type ( ls -l *c ) In The Shell?

What Happens When You Type ( ls -l *c ) In The Shell?

Ebube Agwaze's photo
Ebube Agwaze
·Aug 24, 2021·

3 min read

Background

Linux shell commands are a utility of the Linux operating system. Basic and advanced tasks in the system can be done using the commands. They are executed in the Linux terminal. The terminal is a command-line interface that interacts with the user -or so does the user interact with it -.

Typing ls -l *c in the terminal.

In this post, we discuss how ls -l *.c command works. This is not your typical command-if you have one that is -, but a command followed by an argument and a wildcard. We will explain how it works all together to give it’s output. From the system calls involved to the output. Wear your glasses!

ls

‘ls’ command is one of the most frequently used Linux commands. It is very useful for both beginners and professionals. ‘ls’ lists directory contents of files and directories. How does it know which directory to list it contents? How does it list? And where does the list go?

1.png

How is the list listed?

This must be interesting and educative if you’re still reading. You ask, how does it list the list..hahaha. This is where the flags or arguments come in. The flags format how the list looks. There are tens of ways into which the output can be formatted. Today, we dive into the ‘-l’ argument. ‘ls -l’ gets the details of the directory’s contents. The details include the last modification date/time, the name of the owner,user and group the contents belong to and of course the name of the content and whether it is a file or directory.

3.png

The system calls

So how does the list come to the terminal or to the std output? Or you’d say that’s why you have a screen for(laughs). Launching the terminal is the same as launching your favorite app. Except this time, you don’t get to see you favorite couple’s new insta story! -Forgive me if you don’t use Instagram-. You are presented with a prompt that requires you to enter a command. When a command is entered, the read() system call is issued. The command is passed to the kernel and if valid it is executed. If not found, an error is returned. Another system call is issued. The write(), displays the result of the exec() system call. And that is how the list is listed.

The lost cards

About wildcards. What are they? They are globbing patterns used to perform various actions on more than one file at a time, or to find part of a phrase in a text file. In our command we look at (asterisk) wildcard. It allows us to select a group of files. A pattern can be expressed as: All C programming files — .c, All Perl files starting with an alphabet ‘c’ — c*.pl

The partying shot!

From all of that, I believe that you already know what the output of our command would be. Let us see if we’ve guessed right. ‘ls -l *.c’ lists the contents of the directory it has been run on, in a long listing format — that gives the details of the contents -. Is that so? Not quite. The asterisk wildcard tells our command to only list the c files present in our directory. Congratulations! For getting to the end of our post. Sudo apt install coffee and celebrate.

4.png

5.png

6.png

Thanks...

This is a group project by Mark Tanui and Ebube Agwaze