Linux / UNIX List Just Directories Or Directory Names

https://w‮uttual.ww‬ri.com
Linux / UNIX List Just Directories Or Directory Names

To list just directories or directory names in Linux or UNIX, you can use the ls command with the -d option. This option tells the ls command to list only the directories, rather than the contents of the directories.

For example, to list all directories in the current directory, you can use the following command:

$ ls -d */

This will display a list of all directories in the current directory, one per line.

You can also use the find command to list directories. This command allows you to search for files and directories based on various criteria, such as name, size, and permissions.

To list directories, you can use the following syntax:

$ find . -type d

This will search for directories in the current directory and its subdirectories, and display a list of the directories that were found.

You can also use the find command with the -maxdepth option to limit the search to a certain depth. For example, to search for directories only in the current directory, you can use the following command:

$ find . -maxdepth 1 -type d

You can also use the tree command to list directories and their contents in a tree-like structure. To list directories and their contents, you can use the following syntax:

$ tree -d

This will display a tree-like structure of the directories and their contents in the current directory.

Finally, you can use the find command with the -printf option to display only the names of the directories that were found. For example, to display the names of all directories in the current directory, you can use the following command:

$ find . -type d -printf "%f\n"

This will display a list of the names of all directories in the current directory, one per line.

Created Time:2017-10-29 22:08:55  Author:lautturi