How to list files in a very efficient way?!
What does the ls *.c instruction do at the conceptual level? (regardless of the language used)
Lists the files in the current directory that end in “.c”. You do not understand it?! Take it easy, below I will let you know all the steps you need to know in order to understand it.
Basic concepts
If you have worked in Linux, you may be familiar with the?ls?command. But for everyone else "Ls" is short for “list”. This command lists information about directories and any type of files in the working directory. Let’s start by explaining the syntax of the?ls?command.
[options]?– This lets you add additional instructions to the?ls?command. Example that we will be provided in the following sections of the article is about listing all articles that have a specific identifier regarding the files we want to list.
领英推荐
Explanation of the command step-by-step
In the command ls -l *.c we are going to separate this command step-by-step in order to understand how all this commands are linked together. "ls -l"?command is used to print out a long listing format of files and directories. The output displays information, such as file or folder name, owner of the file and its permission, size and modified date and time as in the image below:
The '*' here is a?wildcard, which matches any number of characters. In Linux if you use '*' and adding every argument after and before it, helps you to check all those files that have those arguments before or after that sign. On our case we are looking to list all the files that ends with ''.c" in long format including information file name, owner of the file and its permissions, size and modified time and date.
Now, what does the instruction ‘ls * .c’ do?
It lists (with the command ls) the current directory (which is the default option of the ls command) the files — files and directories — that start with anything but that necessarily end in ‘* .c’. Then, it reprints you the prompt, giving you again the entry to the Shell.
Stay tuned for more informative blogs! Made by Eno Gupe & Donaldo Kumaraku
Developer Engineer at Digitalb
2 年ls -aril *.c | grep '*str*'