A Step-by-Step Guide: What Happens When You Type "ls *.c" and Hit Enter in Your Shell
Nihad Gurbanov
Java Backend Developer | Spring Boot | Microservices | Java Expert | Lifelong Learner
When you're just starting out with the command line, even the simplest commands can seem mysterious. So, let's take a closer look at what happens when you type ls *.c and hit Enter in your shell. This command is commonly used for listing all files with the ".c" extension in a directory.
1. Typing the Command:
The first step is to open your terminal or command prompt, and then you type the command:
2. Understanding "ls":
3. The "*" (Asterisk):
4. Hitting "Enter":
Once you've entered the command, you press the "Enter" key.
5. Shell Processes the Command:
The shell, which is a command-line interface to your operating system, processes your input. It interprets the command and takes action accordingly.
6. Expanding the Wildcard:
7. Executing "ls":
The ls command now receives the expanded command, which might look something like:
8. "ls" Lists the Files:
9. Viewing the Results:
You'll now see a list of files with the ".c" extension in your current directory, which can be particularly useful if you're working on C programming projects and want to see all your C source files.
10. Working with the Listed Files:
Once you have the list of files, you can use various commands to manipulate or process them. For example, you can compile your C programs using a command like gcc or perform other operations on these files.
In summary, when you type ls *.c and hit Enter in your shell, you're effectively asking the shell to list all files with a ".c" extension in the current directory. The wildcard * is used to match any characters in the filenames, and the ls command displays the results in your terminal, making it a handy tool for managing and organizing your files.