What is the command one can use to list only the directory names?

Before answering this question it is important one should know about ls command in detail in UNIX or LINUX operating system.


ls command without any option is used to list files and this command list files generally in alphabetical order. That is the command list the files present in a directory with one file per line displayed on the screen. Simply using s command without any option display all files names present in the current working directory. If one likes to display files present in a particular directory then they can do that by naming the directory name after ls command. Say for example if one wants to display all files represent in the directory Exforsys they can do that by giving the command as



ls Exforsys



So having known about the ls command now let us see the requirement of displaying only the directory names. This can be done by using the option as –d with ls command. Suppose if one wants to display all directories under the directory /usr/exfor it can be done as



ls –d /usr/exfor/


Showing Answers 1 - 10 of 10 Answers

Milton

  • Oct 11th, 2006
 

ll | grep "^d"

This will display only the lines staring with letter "d" from the "ll" command.

  Was this answer useful?  Yes

Vijayarathinam.R.S

  • May 29th, 2007
 

This following command will list only the directory in the current path
$ ls -l | grep ^d

  Was this answer useful?  Yes

vnanda

  • Jun 22nd, 2007
 

find . -type d

It would list the names of all the directories in current directory recursively.

Thanks

Vikram Nanda

  Was this answer useful?  Yes

djapplegate

  • Oct 12th, 2007
 

for a quick listing of Directories I use ls -d */.
This lists all the dirs at the current file system level.  It doesn`t follow the leaf nodes down the dir structure. 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions