Understanding the [ls *.c] Shell Command

No alt text provided for this image


If you're reading this, you are probably looking to find a more in-depth summary of the command [ls *.c], and you have come to the right place. It is a lot more simple than it looks and with a step by step breakdown it's very easy to understand even for Shell beginners. Let me explain:

Think of this command in two parts. The [ls] is short for list and actually lists out all directories or files depending on which directory you are in. If you type [ls] and hit [Enter] while you're in a certain directory, then you can see all executable and non-executable files (executable files will be green) in the folder. [ls] is extremely helpful and used often.

Now for the other half of this command: [*.c]. The asterisk, also known as "*" is called a wildcard in the world of coding. This character acknowledges the text on either side of it (example* or *example) and with the function [ls] prints a list of files or directories beginning or ending with whatever you are searching for specifically. For example, you have a long list of files but you're looking to find one that begins with a "j". All you have to do is type [ls j*], hit [Enter], and your command line will print every file that starts with a "j". If you wanted to find a file that ends with a "j" then the command is [ls *j]. These are very similar so make sure to keep your eyes on the asterisk!

Now with your new knowledge you will note that all together, [ls *.c] will print all files or directories that end with .c

You can do this as many times as needed and it doesn't change anything about your files. So, go ahead, and try it out! It may guide you to notice the files you don't need or maybe even help you see why your code isn't executing.

To view or add a comment, sign in

More articles by Lauren Dobratz

  • What happens when you type holbertonschool.com in your browser and press Enter

    Some may wonder what goes on behind the scenes when typing in a website domain name. This blog will walk you through…

  • Recursion in Programming

    Recursion is a function that calls itself directly or indirectly. The function will have a base case, and if that case…

  • Python3: Mutable or Immutable?

    Are you confused whether your program's object is mutable or immutable? Are you looking to find answers on how to pass…

  • Dynamic Libraries in C Programming

    Using a library in C is way more useful than to link object files from a separate memory sticks or discs. It is a…

  • Static Libraries in C Language

    What are static libraries? Static libraries are very useful in coding. They are compiled object files (linked during…

  • Symbolic Links vs. Hard Links

    In Linux, there are two separate types of links: hard and symbolic. Let's go over some prerequisites first.

Explore content categories