[juneau-lug] Re: ls directories

  • From: James Zuelow <James_Zuelow@xxxxxxxxxxxxxxx>
  • To: "juneau-lug@xxxxxxxxxxxxx" <juneau-lug@xxxxxxxxxxxxx>
  • Date: Mon, 7 Feb 2011 06:54:43 -0900

Interesting.

You could try:

find /var/log/ -type d

The output is different, and you'll have to explicitly tell find to not descend 
the whole tree to avoid security warnings:

find /var/log/  -maxdepth 1 -type d

The find syntax can get pretty funky when you want to skip directory trees, but 
it is an option if you're using the command in a script.

I tend to use ls when I'm typing, and find when I'm scripting.

James
________________________________________
From: juneau-lug-bounce@xxxxxxxxxxxxx [juneau-lug-bounce@xxxxxxxxxxxxx] On 
Behalf Of Jamie [jamie@xxxxxxxxxxxxxxxxx]
Sent: Friday, February 04, 2011 9:45 PM
To: juneau-lug@xxxxxxxxxxxxx
Subject: [juneau-lug] Re: ls directories

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.
>>>
>> ------------------------------------
>> 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.
> ------------------------------------
> 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.
------------------------------------
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.
------------------------------------
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: