Re: list files but not directory

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

 



On 08/22/09 16:46, quoth Mikkel L. Ellertson:
> Marko Vojinovic wrote:
>> There is just one thing that baffles me here --- isn't a directory also a file? 
>> Given that, what you ask for is not an option to list only files, it is an 
>> option to list everything except directories. In other words, you are asking 
>> for an option that says "list the directory contents, but omit certain 
>> things".
>>
>> The more appropriate way to do this is to use some form of filtering. Such a 
>> thing does not naturally fit into a list of options of ls, IMHO. What you 
>> actually do is perform two operations here --- list the contents, and then 
>> filter it to display only some subset. Two operations should be done using two 
>> commands, the Unix Way. And the filtering approach gives you more flexibility 
>> what file types to filter out. For example, is /dev/sda a file or a directory? 
>> How would this hypothetical ls option behave in this case? List it or not?
>>
>> There are not *just directories and files* on the system. There are
>> *just files*. And these files might be regular files, directories, devices, 
>> stdin/stdout, and who knows what else. You are proposing to add a single 
>> option to ls in order to filter out one of these types. Why only this one type? 
>> Put a whole bunch of options in ls which could list only regular files, or only 
>> character devices, or only hidden directories or... Or better yet, don't put 
>> any of that crap into ls, but pipe the ls output and filter it using a more 
>> appropriate tool.
>>
>> The completely analogous situation is with paging the output of ls. When I 
>> first used ls on a directory with lots of files, the natural idea for me was to 
>> look into its man page to find some option that would split the output into 
>> several screens and display them one by one. I failed to find such an option. 
>> After some digging, I found that this is done via a pipe to less:
>>
>> ls | less
>>
>> And then after some learning I understood that this is actually the better way 
>> to do it (more powerful, more flexible, more clean, more useful). The same 
>> situation is here with listing only non-directories. 
>>
>> The main problem is not lack of functionality, but that Windows-converts have 
>> a frame of mind that makes a distinction between "directory" and "file" 
>> concepts, and believe these concepts are fundamentally different and non-
>> overlapping. This is a Bad Idea, and it seems more appropriate to educate 
>> users than to add options to ls which make it do things it is not designed 
>> for.
>>
>> Just remember: "Do one simple thing and do i well." ;-)
>>
> And to carry this one step farther, you can create aliases or
> function to do things you require often. For example, you could use
> something like this:
> 
> function lsp() { ls $@ && less }
> 
> so that you could run lsd instead of running "ls | less".

Two things!

1. Bash syntax:
This will not work:
function lsp() { ls $@ && less }
If you do it in one line then it would have to be
function lsp() { ls $@ && less; }

If you say ls && less then you will only run the less command if the ls
command succeeds with a 0 exit status. I know this was a typo but I just
didn't want others to get confused.

*NEVER* use $@ without using double quotes. It is very bad luck and failure to
follow this advise will cause you to send 200 copies of stupid jokes to all
the people you know with aol addresses. And worse, you will end up knowing
more aol people.

What's the difference between an alias and a function? Simple: If you need to
pass arguments then use a function. I mention this because it's another of
those basic sources of confusion.

2. READ THIS BOOK!

http://catb.org/~esr/writings/taoup/

This discussion has flowed from complaining about how deficient ls is, to how
people have to learn new paradigms when moving to a new operating system. One
of the worst things that can happen to a knowledgeable Unix engineer is to
have him subjected to a windoze weenie telling how to do it right. There's a
reason that things work and work well in Unix. Do one simple thing and do it
well is really just the tip of the iceberg. In fact, Eric did a great job of
articulating enough stuff to fill an entire book of stuff that all of us
already know but may not have actually ever articulated. For example, lots of
people like C++. Lots of people like using threads. One of the cool spotlights
in the book is why you should be wary of a project that uses both.

Buy it in a book store, print out your own copy, or read it on line. No matter
how much you know, reading this is like running lsd for the first time. ;-)

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