Linux List Directories
There are various methods to list files and directories information about them on Linux systems. But ls is the primary command which we can use for listing files and directories. This command will list files and directory within the file system and displays the complete information. This is a portion of the GNU core utility package, that is installed on each Linux distribution.
How to Use ls Command
If we want to use the ls command, then we have to use the following syntax:
If without any option and parameter we used the ls command then the ls command will show you the list of each file in the present working directory.
When we execute the above command then the files are listed alphabetically in multiple columns which can fit across our terminal:
In order to list the files in a definite directory, we have to pass the directory's path like an argument or parameter to the ls command. For example, in order to list the content of the /etc directory, we have to type the following command:
Listing Directories Using Wildcards
Listing directories using a wildcard is the easiest way to list directories. In this, each directory ends with a forwarding slash.
List Directories Using -F Option and grep
The -F option appends a trailing forward slash. Thus we are able to grep the directories with the help of the 'grep' ing lines that are ending with a forward slash (/);
We can also use the directory names without the -l option
Listing Directories Using -l Option and Grep
In the ls long listing means ls -l, we are able to 'grep' the lines that are starting with d.
Using Echo Command
With the help of the echo command we can list the entries which are trailing with a forward slash (/).
In a similar way, we can use printf to highlight strings which are ending with a forward-slash (/)/
Using Find Command
Using find command, we can find the files on the basis of their file types.
In the above command, the maxdepth option specifies that the search is performed on a particular directory only. Otherwise, find command will recursively find the directories by traversing each directory and its subdirectories. In all the above methods, which we used in the ls command, we can achieve the same via the -a option. For example:
List Subdirectories Recursive
The -R option tells the ls command to show the content of the subdirectories in the recursive manner: