What happens when you type ‘ls *.c’ and hit enter in your shell?

As a software engineer student, I should know most of commands and explain it to the others who are curious about the software. In this article I will explain what will happen when we type ls *.c ? . Before that I need to define what is The Shell and terminal .

1-What Is The Shell?

When we speak of the command line, we are really referring to the shell. The shell is a program that takes keyboard commands and passes them to the operating system to carry out. Almost all Linux distributions supply a shell program from the GNU Project called bash. The name “bash” is an acronym for “Bourne Again SHell”, a reference to the fact bash is an enhanced replacement for sh, the original Unix shell program written by Steve Bourne.

2-What’s a terminal?

      It’s a program called terminal emulator. A terminal is a text-based interface that allows you to type and execute commands to your operating system.

3-What happen when we type ls :

    The “ls” command is a command-line utility for listing the contents of a directory or directories via standard input. It writes results to standard output. To show the contents of a directory pass the directory name to the ls command. This will list the contents of the directory in alphabetical order..

sort-ls-output-by-modified-date-and-time

4- What happen when we type ls *.c :

1. ls command lists files and directories.

2. ls command can be followed by options and arguments to supplement the functionality of the command.

3. * — is a wildcard character that can be used as a substitute for an array of characters in a search.

4. * — can be used with strings or characters/symbols to refine or modify parameters of a search.

5. ls *(string) will result in finding any and all files with the string pattern at the ending of the filename. Vice-versa if we do it ls (string)* it will search for the string pattern at the beginning of the filename.

6. ls *.c will try to list all files with the .c extension, if no files are found the command line output prompt will be something like this “ls: cannot access *.c: No such file or directory”

 

 

 

 

Leave a comment