Linux List DirectoriesThere 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 CommandIf 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 WildcardsListing directories using a wildcard is the easiest way to list directories. In this, each directory ends with a forwarding slash. Syntax: List Directories Using -F Option and grepThe -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 (/); Syntax: We can also use the directory names without the -l option Syntax: Listing Directories Using -l Option and GrepIn the ls long listing means ls -l, we are able to 'grep' the lines that are starting with d. Syntax: Using Echo CommandWith the help of the echo command we can list the entries which are trailing with a forward slash (/). Syntax: Using printfIn a similar way, we can use printf to highlight strings which are ending with a forward-slash (/)/ Syntax: Using Find CommandUsing find command, we can find the files on the basis of their file types. Syntax: 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: Syntax: List Subdirectories RecursiveThe -R option tells the ls command to show the content of the subdirectories in the recursive manner: Next TopicLinux Shortcuts |