Organization lesson

What happens when you type ls *.c

Checha Giudice
5 min readSep 20, 2020

Did you, my dear reader, ever wonder that, if you could only organize your closet (because you can’t ever find your favorite shirt, your shoes are never with their respective partner and somehow there’s a loose sock on the inside of your jean’s pocket), you could actually get your life together? Didn’t you? Only me?

And what about your digital files? In my personal experience working as a graphic designer, I came to the conclusion that: I am a great designer (not to brag) with poor organization skills.

I had to create a new folder for each day of work, but had to edit templates and images that were saved on another file. At the same time, I had to use
different programs to get the result I wanted, such as Photoshop, Illustrator, AfterEffects (and others).

But what was all that about my poor organization skills? Naming the files. I would name a Photoshop file the same as an Illustrator file. Stupid, right? But when your task of the day is to create 78 (yes, seventy eight) different images with a single quote for your boss to choose from, and then changing lighting and contrast of each one of them (because your boss needed them to be brighter and happier), you start to loose track of what name you finally save your file with, or even if you actually change it to distiguish it.

To be more illustrative, go to my closet example.

What does that has to do with “ls *.c”?

Well, if my closet had some sort of app (I’m thinking Cher’s PC on Clueless, but with an upgrade), all of my shoes will be paired, my blue jeans wouldn’t be mixed with my sport pants, and there would be no loose sock inside any pocket. It would be closet paradise.

That’s what this command does in Linux (it would find the sock inside the jean pocket, so to speak).

Start at the beggining… Divide and conquer!! Open your linux console and try each part.

$ ls *.c
  • ls — The ls command is one of the basic commands that any Linux user should know. It is used to list information about files and directories within the file system. The ls utility is a part of the GNU core utilities package which is installed on all Linux distributions. Try ls on your console.

You should look be looking at something like this:

this ls command show the inside of the folder /holberton-system_engineering-devops, which are another five folders, and a README.md file.

In this special case, you are able to find which folder/file you need because ls displays only six items. The thing is, what if you had the 78 files that I talked about in my example before? Your screen couldn’t hold up that many files, you would have to scroll, and In these moments where time is money we need to limit the action of the command, we must tell ls to limit its response.

So I present you with: wildcards.

Commands can use wildcards to perform actions on more than one file at a time, or to find part of a phrase in a text file. Given that what we want is to find is the red sock inside the jean, we will talk about our next item in the ls *.c:

  • * — this can represent any number of characters (including zero, in other words, zero or more characters). If you specified a “cd*” it would use “cda”, “cdrom”, “cdrecord” and anything that starts with “cd” also including “cd” itself. “m*l” could by mill, mull, ml, and anything that starts with an m and ends with an l.

“*” you could say it means “everything that matches”. But you need to tell what you want to match. Like in the example given before you need to specify if you want to match what’s first o what’s last in that line of text.

Let’s get back to those 78 files. Imagine that every file was named “quote” next to a number (like quote01 and quote 54). But I wanted to find quote22. With ls I would type ls *22 on my console and that would display the quote22 file because there’s only one file named quote ending with 22.

“*” works the other way around. If the files were named with the number first, and I wanted to find the 22file, I would type ls 22*. The order of the product alters the result.

Let’s try that. We know there’s a file called README.md inside the folder. If we wanted to find that particular file we would type ls *.md and the command would display the README.md file.

And that’s it!

I’m kidding,we are still missing the final step:

  • .c — This is the part that will actually limit our command. We are telling the ls command to look for every file that ends with a “.c”. The . (dot) is indicating file extension, and c the file extension for a C program.

Let’s try everything on our console. I’m going to use the previous folder and then another folder containing .c files so that you can understand both outputs.

First, the previous folder, the one that did not contain any .c files.

The complete command doesn’t work because there are no files in that folder that have the extension .c.

Let’s try the complete command on this other folder.

You can see that the ls *.c command only displays de .c files. So it worked perfectly.

Going back to whats important (and by that I mean my closet), I think ls *.jean would find the jean that holds prisioner my red sock. Am I right?

Hope this blog lights your way, my dear reader. :)

--

--