[juneau-lug] Re: ls directories

  • From: Mark Neyhart <Mark_Neyhart@xxxxxxxxxxxxxxxxx>
  • To: "juneau-lug@xxxxxxxxxxxxx" <juneau-lug@xxxxxxxxxxxxx>
  • Date: Mon, 07 Feb 2011 10:49:53 -0900

As far as I can tell, the -d option does not mean to list only files
which are directories, but instead means for any file which is a
directory, list ONLY its name, NOT its contents.

Also, remember that the shell is responsible for * expansions.  So
when you specify

$ls -dl /*

it is the same as using the output of

$echo /*

as the file name list for ls -dl [FILE]...

I think that the reason your first two examples worked as you expected
is probably because you have nothing BUT directories in your root
directory and nothing BUT directories in your /var directory.

Jamie wrote:
> OK found an answer - it needs a final slash:
> ls -dl /var/log/*/
> 
> Still unclear why it is successful at the higher levels without the 
> final slash?
> 
> On 02/04/2011 09:36 PM, Jamie wrote:
>> As you suggest, I can get what I want piping grep:
>> ls -dl /var/log/* | grep ^d
>>
>> But why should I need to do this?  It's hard to believe there is a bug
>> in ls.  Yet if this is a feature, where is it documented?
>>
>>
>> On 02/04/2011 07:35 PM, woolsherpahat wrote:
>>> maybe something like this?
>>>
>>> ls -Rl /var | grep '^d'
>>>
>>> On Fri, Feb 4, 2011 at 8:04 PM, Jamie<jamie@xxxxxxxxxxxxxxxxx>   wrote:
>>>> ls , the most basic, simple command we have, right?  Can someone
>>>> enlighten me on listing directories, using the -d option.  Here is what
>>>> I find
>>>>
>>>> ls -dl /*        works, lists just the directories
>>>> ls -dl /var/*        works
>>>> ls -dl /var/log/*        lists files and directories -HUH?
>>>>
>>>> In fact, anytime I ask for more than 2 levels of depth, it includes
>>>> files.  I don't want them listed.  Is there a way?
>>>> ------------------------------------
------------------------------------
The Juneau Linux Users Group -- http://www.juneau-lug.org
This is the Juneau-LUG mailing list.
To unsubscribe, send an e-mail to juneau-lug-request@xxxxxxxxxxxxx with the 
word unsubscribe in the subject header.

Other related posts: