What is the command that I can use in Linux to list the directory name alone. Could someone help me out in this?
Printable View
What is the command that I can use in Linux to list the directory name alone. Could someone help me out in this?
You can use the option –d or the directory command line option with the ls command. Suppose you want to list the directory names alone starting with a in directory /usr/x you can do that as follows:
ls –d /use/x/a*
In linux there is no direct way of listing directories,hence we combine the [B]ls[/B] command with [B]grep[/B] and [B]type[/B] as follows:
1. use ls -l with grep
2. use find -type d
Example:
1.ls -l | grep "^d" -The simple way to list just directories, is using ls -l pipe with grep
2.find -L -maxdepth 1 -type d -name
here -L is to show also for the symbolic link to directory, -maxdepth limit the search up to only 1 level, -type d indicates that the file must be directory.