Working with files in shell

Working with files in shell

What happens when you type "ls *.c" in shell

What is shell?

Shell helps the operating system interprets commands and translates them into machine language that can be understood and used by the kernel. Operating systems can use shell in a form of a command-line interface or graphical user interface. Different operating systems have their own default shell. In this article, we will be using Bash which is the default shell of Linux.

Working with files on shell

ls

ls is a command that is used a lot when working with files in shell. It is used to list the files in a directory and can be used with many other options, as well as with wildcards. for example

ls -l

is used to display files in long format. It can also list the permissions of files.

ls can be modified by options that came after it.

ls -C

will output files in that specific directory in columns.

ls -a

will list all files, including the hidden files. There are more than 25 options that can be used with the ls command.

What happens when you type "ls *.c"?

As previously discussed, ls will list all files in a directory. "*" is a wildcard. A wildcard means a substitute for anything. It is used to match any character in a file,filename,or even a directory.

ls *.c

When you type this command, shell will list of filenames in a directory that ends with an extension of c. For example, if you have files names like "shell.c" or "hello.c" those files will be outputted but any file that ends with any other extension will not be outputted.

Did you find this article valuable?

Support Thandiwe Khalaki by becoming a sponsor. Any amount is appreciated!