Re: list files but not directory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 08/21/09 10:35, quoth William Case:
> Hi;
> 
>> Seems like a very reasonable request and its a shame that ls does not 
>> provide such an option (which I guess would be an extension to the -A 
>> option)
>> 
> 
> I remember asking about this four or five years ago when I first started 
> using Linux (RedHat). (It was the first question I asked on the users 
> mailing list.)
> 
> Now that I am familiar with 'find' and 'grep' etc. I no longer worry about
> it.  However, 'ls' is probably the first commandline command a beginner
> learns.  It seems illogical, that 'ls' wouldn't have a flag that just shows
> files when it has a flag for directories.  It can cost newbies hours
> looking for a solution that isn't there.
> 
> Couldn't the shell maintainers just add an appropriate flag to show files
> only?

My take is that the ls command is already so heavily loaded with options that
you're better off rolling your own. For example, let's beuild two new
commands. lsd and lsD. lsd will only list directories and lsD will only list
nondirectories.

lsD ()
{
    typeset args1="$1"
    typeset args2="$2"

    ls -la $args1 | awk '!/^d/ {print $9}' | xargs ls $args2
}

Now you can try things like
lsd '-d x*' -l

and lsd is left as an exercise for the student. ;-)

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux