Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 05-25-2004, 05:49 PM   #1
Registered: May 2004
Location: Italy
Posts: 70

Rep: Reputation: 16
How to see just dirs with ls?

Once I learned all Linux basic commands and read the man page for "ls", I'm still wondering how can I list ONLY directories (hidden and not) within the ls default output form (columns).
If I want to see only the directories of a path, I use the following:
ls -la | grep "^d"
ls -laF | grep "/"
but I don't want directories listed (flag -l) in just one column, I want 'em distributed in moltiple columns without file permissions, owner, groups, etc...
How can I do this?
I realised there's no way for ls to simply show just directories and nothing else.
Could you give me an help, please?
Thanks a lot guys!
Old 05-25-2004, 06:12 PM   #2
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Here's something you can play with. It won't get the directories in columns though (unless you turn it into a script and do some magic).

find -maxdepth 1 -type d | cut -d / -f 2 | grep -v "^\." | sort

The cut command simply prunes the ./ at the beginning of every directory find returns

The grep command filters out the hidden directories

The sort command, well, sorts them alphabetically
Old 05-25-2004, 06:32 PM   #3
LQ Newbie
Registered: Mar 2004
Location: USA
Distribution: Mandriva
Posts: 20
Blog Entries: 5

Rep: Reputation: 0
Here are a couple of options to play around with.
find . -type d -maxdepth 1
ls -a | grep /
ls -d */ gives unhidden directories but ls -da */ doesn't work as I expected.
good luck
Old 06-04-2004, 11:45 AM   #4
Registered: May 2004
Location: Italy
Posts: 70

Original Poster
Rep: Reputation: 16

ls -d .*"/" *"/"



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
Symlink two dirs into one? neocookie Linux - General 7 05-27-2005 09:50 AM
add dirs to $PATH zchoyt Linux - General 4 09-13-2004 03:00 PM
ls, dirs first, files later TroelsSmit Linux - Newbie 4 05-31-2004 12:47 PM
removing dirs... chrismiceli Linux - General 5 10-25-2002 06:16 AM
hidden dirs? mighty Linux - General 3 11-03-2001 04:38 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:55 AM.

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