Magic for beginners, or what the Unix `ls *.c` command does.

Sergii Garkusha
3 min readJan 17, 2018

For those of us who only starting with programming, terminal looks like a window to a world of magic, and that magic sometimes looks dark. This is not surprising, especially if our padawan sees something like this:

However, this array of mystical symbols is a helpful command full of sense. And if we will overcome the fear and try to read it, we will be able to find some patterns, even if we don’t know the syntax. What we can see here is that it looks like a chain — the chain of small commands. And for today I’m going to demystify one of the commands similar to them— the ls command.

According to Wikipedia, ls is a command to list files in Unix and Unix-like operating systems. That is, it does basically one thing — it displays the listing of some particular directory.

The first time ls appeared in the original version of AT&T UNIX, and it’s a short for the word “list”. Also it is one of the oldest commands that we still using today (almost 50 years from now).

While in its basic usage it is very simple, ls have a long list of optional arguments we can include. So like most man pages, the ls manual page is daunting to read (it has exactly 214 lines on Linux operating system).

But I’m not going to retell you the manual (if you want to know the reason, google for RTFM please). Today I’ll talk more about using ls to find specific files with extensions: ls *.c

Running ls without any arguments just lists the files and directories in the current directory, one after another.

So what is the purpose of *?

The asterisk character (also called "star") acts as a wildcard for the filename expansion, and the fun part is that with ls we can search for patterns in the filenames with it.

And as you probably guessed, ls *.c will help us to find all the files that have .c extension, no matter what names they have. Literally that means: “find files that have any name with the .c at the end.”

In my case the result of running the command looks like this:

Incredibly useful, huh?

P.S. Concerning that very long command from above — I’m not going to demystify it today, but you can try to play with it yourself. And here’s the nasa_19950801.tsv file:

wget http://indeedeng.github.io/imhotep/files/nasa_19950801.tsv

That’s all for today, folks!

--

--

Sergii Garkusha

Hacker. 500 Startups Alumni. Envato Elite. School of AI Dean. Runner. Ukrainian. I write about software, AI & life. SF 🌁 https://cu7io.us