list files but not directory
Mikkel L. Ellertson
mikkel at infinity-ltd.com
Sat Aug 22 20:46:37 UTC 2009
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".
Mikkel
--
Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
Url : http://lists.fedoraproject.org/pipermail/users/attachments/20090822/454c8ede/attachment-0001.bin
More information about the users
mailing list