LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to just list directories using ls command (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-just-list-directories-using-ls-command-259391/)

shazam75 11-25-2004 11:58 PM

How to just list directories using ls command
 
Hi

How do i use the ls command to just list the directories in a particular folder?

Regards
Shelton.

twantrd 11-26-2004 12:14 AM

To list just directories of a particular directory:

ls -l <dir> | grep ^d

If you are inside the directory and just want to the list only directories then it's:

ls -l | grep ^d

At least that's what I use :). Other's my use different commands.

-twantrd

Oliv' 11-26-2004 04:11 AM

Hi,

or simpler: ls -d

Oliv'

theYinYeti 11-26-2004 04:53 AM

No. ls -d is for displaying a directory "the same as" a file, that is not displaying it's content. Example: you want to see all hidden files (beginning with a .), but you don't want to list the whole content of . and ..
Code:

ls -ad .*
Now, to get the list of directories, I would do:
Code:

find . -mindepth 1 -maxdepth 1 -type d -print
Yves.

uberNUT69 01-26-2006 03:28 AM

Simpler:

Code:

ls -d */

shazam75 01-26-2006 03:35 AM

wow that is handy indeed!

thanks
shelton.

uberNUT69 01-26-2006 05:38 AM

np, north islander!

being Australia Day 'n' all :)

my 2nd head found the answer ;)

muha 01-26-2006 07:43 AM

I also like this one:
ls *
List all dirs and recurse one dir down.

aragorn_linux 01-26-2006 02:03 PM

My favorite is this:

'ls -al | sed /^d/!d'

This will list all the .directories, and in the format I prefer.

Tinkster 01-26-2006 02:26 PM

Quote:

Originally Posted by aragorn_linux
My favorite is this:

'ls -al | sed /^d/!d'

This will list all the .directories, and in the format I prefer.

you mean
Code:

ls -al | sed '/^d/!d'
?
The version you posted won't work with bash.

Cheers,
Tink

Jelle 01-26-2006 02:34 PM

too much typing. I usually ploink such things in an alias or function in ~/.bashrc. My most recent entries there were
Code:

alias lrt="ls -lrt" alias cdl="cd $1; ls --color=auto"
I use the lrt command quite a lot, it usually shows he files you are interested in on the last few lines, instead of having to remember how the alphabet works :-)


All times are GMT -5. The time now is 04:44 PM.