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

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

Let's make this as simple as possible, this article is for Absolute Beginners

Before we talk about the ls command, let's take a look at what Terminal means

What is terminal ?

Graphical user interfaces (GUIs), allow you to to accomplish daily tasks by interacting with windows and icons, and are helpful for many tasks. However, for many tasks, we are better off entering text commands into the computer directly for more efficiency and flexibility. We usually do this through terminals. It lets you interact indirectly with the system by using commands.

Then .. what is "ls" ?

The ls command is a command-line utility for listing the contents of a directory or directories given to it via standard input. It writes results to standard output. The ls command supports showing a variety of information about files, sorting on a range of options and recursive listing.

Aucun texte alternatif pour cette image

Let's take a look at this example, I typed ls command in my home directory and the I press "enter", ls prints directories and files who are in my home directory

But what does " * " refer to ?

* means "Matches any characters", it's a wildcard command. We use it in all linux commands to mention the names of the files or directories we want to display.

So ! What happens when we type ls *.c ?

In this case, *.c will match any filenames that end with the extension ‘.c’. So, what does ls *.c do? You guessed it! The script lists all filenames ending with the ‘.c’ extension in your current directory or folder.

Aucun texte alternatif pour cette image

How does this work exactly?

Simply with alias (which is a shortcut to reference a command. It can be used to avoid typing long commands or as a means to correct incorrect input. For common patterns it can reduce keystrokes and improve efficiency) and shell expansion (which is a process that occurs when a character or symbol expands into larger text or output), like in this case the ‘*’ will perform the expansion to find all files and directories ending with the ‘.c’ extension.



要查看或添加评论,请登录

Mohamed Chaabane的更多文章

社区洞察

其他会员也浏览了