Javatpoint Logo
Javatpoint Logo

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:

Linux List Directories

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:


Linux List Directories

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.

Syntax:


Linux List Directories

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 (/);

Syntax:


Linux List Directories

We can also use the directory names without the -l option

Syntax:

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.

Syntax:


Linux List Directories

Using Echo Command

With the help of the echo command we can list the entries which are trailing with a forward slash (/).

Syntax:


Linux List Directories

Using printf

In a similar way, we can use printf to highlight strings which are ending with a forward-slash (/)/

Syntax:


Linux List Directories

Using Find Command

Using find command, we can find the files on the basis of their file types.

Syntax:


Linux List Directories

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:


Linux List Directories

Linux List Directories

List Subdirectories Recursive

The -R option tells the ls command to show the content of the subdirectories in the recursive manner:


Linux List Directories
Next TopicLinux Shortcuts





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA