LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 11-26-2004, 12:58 AM   #1
shazam75
Member
 
Registered: Oct 2004
Location: Australia, Brisbane
Distribution: Gentoo
Posts: 296

Rep: Reputation: 30
Cool 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.
 
Old 11-26-2004, 01:14 AM   #2
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
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
 
Old 11-26-2004, 05:11 AM   #3
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Hi,

or simpler: ls -d

Oliv'
 
Old 11-26-2004, 05:53 AM   #4
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
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.
 
Old 01-26-2006, 04:28 AM   #5
uberNUT69
Member
 
Registered: Jan 2005
Location: Tasmania
Distribution: Xen Debian Lenny/Sid
Posts: 578

Rep: Reputation: 30
Simpler:

Code:
ls -d */
 
Old 01-26-2006, 04:35 AM   #6
shazam75
Member
 
Registered: Oct 2004
Location: Australia, Brisbane
Distribution: Gentoo
Posts: 296

Original Poster
Rep: Reputation: 30
wow that is handy indeed!

thanks
shelton.
 
Old 01-26-2006, 06:38 AM   #7
uberNUT69
Member
 
Registered: Jan 2005
Location: Tasmania
Distribution: Xen Debian Lenny/Sid
Posts: 578

Rep: Reputation: 30
np, north islander!

being Australia Day 'n' all

my 2nd head found the answer
 
Old 01-26-2006, 08:43 AM   #8
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
I also like this one:
ls *
List all dirs and recurse one dir down.
 
Old 01-26-2006, 03:03 PM   #9
aragorn_linux
LQ Newbie
 
Registered: Jun 2005
Location: So. Calif.
Distribution: SuSE
Posts: 1

Rep: Reputation: 0
My favorite is this:

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

This will list all the .directories, and in the format I prefer.
 
Old 01-26-2006, 03:26 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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
 
Old 01-26-2006, 03:34 PM   #11
Jelle
Member
 
Registered: Feb 2004
Location: Utrecht, The Netherlands
Distribution: Debian
Posts: 79

Rep: Reputation: 15
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 :-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] command to list directories only frieza Linux - Software 15 08-03-2013 06:20 PM
list sub-directories only CowboyJ Linux - Newbie 1 12-05-2003 12:42 AM
Asking LS for a list of directories only gary knott Linux - Newbie 1 11-12-2003 06:49 PM
list of directories greg108 Linux - Newbie 5 08-08-2003 04:11 AM
How may I list only the directories in command line? geraldomanaus Linux - Newbie 5 03-20-2003 01:40 PM


All times are GMT -5. The time now is 10:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration