Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #26708 > unrolled thread

ls question -- dirs only

Started bypH <wb6dwp@gmail.com>
First post2019-04-19 13:22 -0700
Last post2019-04-20 09:30 +0100
Articles 11 — 9 participants

Back to article view | Back to comp.os.linux.misc


Contents

  ls question -- dirs only pH <wb6dwp@gmail.com> - 2019-04-19 13:22 -0700
    Re: ls question -- dirs only Bit Twister <BitTwister@mouse-potato.com> - 2019-04-19 15:39 -0500
    Re: ls question -- dirs only Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2019-04-19 16:51 -0400
    Re: ls question -- dirs only Grant Taylor <gtaylor@tnetconsulting.net> - 2019-04-19 14:53 -0600
      Re: ls question -- dirs only pH <wb6dwp@gmail.com> - 2019-04-19 19:37 -0700
        Re: ls question -- dirs only Andreas Kohlbach <ank@spamfence.net> - 2019-04-20 12:10 -0400
    Re: ls question -- dirs only "Carlos E. R." <robin_listas@es.invalid> - 2019-04-19 22:56 +0200
    Re: ls question -- dirs only Robert Heller <heller@deepsoft.com> - 2019-04-19 16:18 -0500
    Re: ls question -- dirs only Eli the Bearded <*@eli.users.panix.com> - 2019-04-19 21:28 +0000
      Re: ls question -- dirs only Grant Taylor <gtaylor@tnetconsulting.net> - 2019-04-19 20:41 -0600
    Re: ls question -- dirs only The Natural Philosopher <tnp@invalid.invalid> - 2019-04-20 09:30 +0100

#26708 — ls question -- dirs only

FrompH <wb6dwp@gmail.com>
Date2019-04-19 13:22 -0700
Subjectls question -- dirs only
Message-ID<d8592e3c-9c8c-4be8-a604-ba040e2b41b8@googlegroups.com>
Is there a way to make ls display only directories?

I've looked through the man pages. The  "--group-directories-first" toggle works fine but is there a way to list the directories *only*?

Pureheart

[toc] | [next] | [standalone]


#26710

FromBit Twister <BitTwister@mouse-potato.com>
Date2019-04-19 15:39 -0500
Message-ID<slrnqbkcfr.udo.BitTwister@wb.home.test>
In reply to#26708
On Fri, 19 Apr 2019 13:22:14 -0700 (PDT), pH wrote:
> Is there a way to make ls display only directories?
>
> I've looked through the man pages. The  "--group-directories-first" toggle works fine but is there a way to list the directories *only*?

All I can suggest is write a bash script, use stat to decide if item
is a directory. If item is a link, check its target to see if it is
a directory.

[toc] | [prev] | [next] | [standalone]


#26714

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2019-04-19 16:51 -0400
Message-ID<q9dcbp$ik7$1@dont-email.me>
In reply to#26708
pH wrote:

> Is there a way to make ls display only directories?
> 
> I've looked through the man pages. The  "--group-directories-first" toggle
> works fine but is there a way to list the directories *only*?

Either (POSIX/SUS)
  find path/to/top/directory -type d -exec ls -d {} \;
or (GNU)
  find path/to/top/directory -type d -ls

As in
  find /etc -type d -exec ls -d {} \;
  or
  find /etc -type d -ls
or
  find . -type d -exec ls -d {} \;
  or
  find . -type d -ls
or
  find $HOME -type d -exec ls -d {} \;
  or
  find $HOME -type d -ls

HTH
-- 
Lew Pitcher
"In Skills, We Trust"

[toc] | [prev] | [next] | [standalone]


#26715

FromGrant Taylor <gtaylor@tnetconsulting.net>
Date2019-04-19 14:53 -0600
Message-ID<q9dcq3$3jp$1@tncsrv09.home.tnetconsulting.net>
In reply to#26708
On 4/19/19 2:22 PM, pH wrote:
> Is there a way to make ls display only directories?

try:

    ls -d */

You can do some fancier things with Zsh, including specifying the type 
of file to include / exclude in a glob.

    ls -d *(/)

The "-d" parameter tells ls to only list what is specified and not the 
contents of what is specified if it's a directory.

The */ and *(/) specify the directories.

> I've looked through the man pages. The  "--group-directories-first" 
> toggle works fine but is there a way to list the directories *only*?

You can do things with find too.



-- 
Grant. . . .
unix || die

[toc] | [prev] | [next] | [standalone]


#26724

FrompH <wb6dwp@gmail.com>
Date2019-04-19 19:37 -0700
Message-ID<319d7419-faba-4b9e-9fee-c4f2bffb7275@googlegroups.com>
In reply to#26715
On Friday, April 19, 2019 at 1:53:39 PM UTC-7, Grant Taylor wrote:
> On 4/19/19 2:22 PM, pH wrote:
> > Is there a way to make ls display only directories?
> 
> try:
> 
>     ls -d */
> 

That works here.  Thanks.
I'm always impressed that there are so many ways to skin the cat and it helps that good old learning curve.

I had thought that I was simply overlooking a listed toggle.

pH


<snip>

> You can do things with find too.
> 
> 
> 
> -- 
> Grant. . . .
> unix || die

[toc] | [prev] | [next] | [standalone]


#26757

FromAndreas Kohlbach <ank@spamfence.net>
Date2019-04-20 12:10 -0400
Message-ID<87pnpgmzd1.fsf@usenet.ankman.de>
In reply to#26724
On Fri, 19 Apr 2019 19:37:17 -0700 (PDT), pH wrote:
>
> On Friday, April 19, 2019 at 1:53:39 PM UTC-7, Grant Taylor wrote:
>> On 4/19/19 2:22 PM, pH wrote:
>> > Is there a way to make ls display only directories?
>> 
>> try:
>> 
>>     ls -d */
>> 
>
> That works here.  Thanks.
> I'm always impressed that there are so many ways to skin the cat and it helps that good old learning curve.

And indeed you can always pipe the result from what ever you wanted
through cat.

ls -d */ | cat -

You can add eight more " | cat -" after that to get nine lives of a cat.

:-D
-- 
Andreas

My random thoughts and comments
https://news-commentaries.blogspot.com/

[toc] | [prev] | [next] | [standalone]


#26716

From"Carlos E. R." <robin_listas@es.invalid>
Date2019-04-19 22:56 +0200
Message-ID<ghur0dFk5l0U2@mid.individual.net>
In reply to#26708
On 19/04/2019 22.22, pH wrote:
> Is there a way to make ls display only directories?
> 
> I've looked through the man pages. The  "--group-directories-first" toggle works fine but is there a way to list the directories *only*?

Try "tree -d" instead. You will have to play with the options to get a 
similar or to your liking display.

-- 
Cheers,
        Carlos E.R.

[toc] | [prev] | [next] | [standalone]


#26717

FromRobert Heller <heller@deepsoft.com>
Date2019-04-19 16:18 -0500
Message-ID<Y5OdnRZbtJmKpifBnZ2dnUU7-T_NnZ2d@giganews.com>
In reply to#26708
At Fri, 19 Apr 2019 13:22:14 -0700 (PDT) pH <wb6dwp@gmail.com> wrote:

> 
> Is there a way to make ls display only directories?
> 

> I've looked through the man pages. The "--group-directories-first" toggle
> works fine but is there a way to list the directories *only*?

find . -type d -maxdepth 1|xargs ls -d

> 
> Pureheart
>                                                                                         

-- 
Robert Heller             -- 978-544-6933
Deepwoods Software        -- Custom Software Services
http://www.deepsoft.com/  -- Linux Administration Services
heller@deepsoft.com       -- Webhosting Services
                                                                                

[toc] | [prev] | [next] | [standalone]


#26719

FromEli the Bearded <*@eli.users.panix.com>
Date2019-04-19 21:28 +0000
Message-ID<eli$1904191728@qaz.wtf>
In reply to#26708
In comp.os.linux.misc, pH <wb6dwp@gmail.com> wrote:
> Is there a way to make ls display only directories?

The way I solve this (which doesn't need zsh like that other follow-up
implies) is:

   ls -d */

Works in /bin/ksh, /bin/bash, /bin/sh, and "/bin/busybox sh" on my system.
I don't have zsh or any *csh variant installed to test. /bin/sh is dash
here.

Elijah
------
simpler than using find

[toc] | [prev] | [next] | [standalone]


#26725

FromGrant Taylor <gtaylor@tnetconsulting.net>
Date2019-04-19 20:41 -0600
Message-ID<q9e16c$64l$1@tncsrv09.home.tnetconsulting.net>
In reply to#26719
On 4/19/19 3:28 PM, Eli the Bearded wrote:
> which doesn't need zsh like that other follow-up implies

How does saying "you can do fancier things with Zsh" /after/ providing a 
solution that works in bash imply that Zsh needed?



-- 
Grant. . . .
unix || die

[toc] | [prev] | [next] | [standalone]


#26733

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2019-04-20 09:30 +0100
Message-ID<q9elbh$4ig$3@dont-email.me>
In reply to#26708
On 19/04/2019 21:22, pH wrote:
> Is there a way to make ls display only directories?
> 
> I've looked through the man pages. The  "--group-directories-first" toggle works fine but is there a way to list the directories *only*?
> 
> Pureheart
> 
  well you could

ls -lR | grep "^d"

for a start...

And then pipe that through awk to remove all but the name.

;-)



-- 
“The fundamental cause of the trouble in the modern world today is that 
the stupid are cocksure while the intelligent are full of doubt."

    - Bertrand Russell

[toc] | [prev] | [standalone]


Back to top | Article view | comp.os.linux.misc


csiph-web