Re: list files but not directory

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

 



> On Sat, Aug 22, 2009 at 03:59:30 -0400,
>   William Case <billlinux@xxxxxxxxxx> wrote:
> > All that I am saying is that it would be handy to have a simple util
> > that listed file names.  I suggest 'ls' because it is probably the most
> > used and first learned listing utility and therefore would be the place
> > to have it.  It would be useful to beginners (particularly those who do
> > not yet have any idea what a regexp is) and for script writing or piping
> > to sed, awk, grep or a new file (or for appending).

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." ;-)

HTH, :-)
Marko


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