GNU bug report logs -
#14189
ls -d bug ??
Previous Next
Full log
Message #21 received at 14189 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 04/11/2013 03:13 PM, Bob Proulx wrote:
>
> If you didn't want it to list only the name of the directory and not
> the contents then why did you use the -d option? Since -d
> specifically prevents it from listing the contents.
>
>> ls -d, I would think, would tell you the same data that ls would tell you, minus
>> the individual files.
>> (In other words - show all the data with a "d" in the permissions, but not show
>> the ones that don't have a "d" in the permissions).
>
> Perhaps you want this?
>
> $ ls -log | grep ^d
> $ ls -log | grep -v ^d
>
> Or one of these:
>
> $ find . -maxdepth 1 -type d -ls
> $ find . -maxdepth 1 -type d -exec ls -logd {} +
Or you could use this to approximate things:
$ ls -d */
the trailing slash forces the shell to filter out non-directories as
part of expanding the glob, and then list just the names instead of the
contents of all remaining directories. But as written that only lists
non-hidden directories. If you don't mind listing '.', you can get
closer with:
$ ls -d */ .*/
But for a full list of all subdirectory names excluding '.' and '..',
you need three globs; and either a shell option that suppresses a glob
that has no match, or ignoring the errors when ls tries to warn you when
a glob doesn't match:
Portable (but risks hiding errors):
$ ls -d */ .[!.]/ .??*/ 2>/dev/null
bash-specific:
$ (shopt -s nullglob; ls -d */ .[!.]/ .??*/)
All the sudden, the 'find' alternative suddenly seems nicer :)
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
This bug report was last modified 12 years and 96 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.