Re: Re:Re: Cat a directory

From: Mark (admin_at_asarian-host.net)
Date: 09/25/03

  • Next message: Micheal Patterson: "Re: FreeBSD and SMP support"
    Date: Thu, 25 Sep 2003 03:42:50 GMT
    To: <freebsd-questions@freebsd.org>
    
    

    ----- Original Message -----
    From: "Matthew Hunt" <mph@astro.caltech.edu>
    To: "Karlsson Mikael HKI/SOSV" <mikael.karlsson@hel.fi>
    Cc: <freebsd-questions@freebsd.org>
    Sent: Monday, September 22, 2003 6:26 PM
    Subject: Re: Re:Re: Cat a directory

    > "cat /bin" on Solaris 9 does exactly the same thing as on FreeBSD; shows
    > the contents of the directory, just like you're asking it to. Just because
    > you can't fathom a use for this behavior doesn't mean it's wrong. If you
    > don't want to see it, don't ask "cat" to show it to you.

    Answers like this are not uncommon. I guess because it evokes the old "This
    separates the men from the boys" attitude.

    However, the purpose of "cat" is to write the contents of a file to STDOUT.
    And yes, in UNIX pretty much everything is considered a file. But that does
    not change the fact that people do not experience a directory as a file, and
    in their use of language also clearly differentiate between the two. You
    too. Besides, for the regular use of writing the contents of a directory to
    STDOUT, "ls" was created.

    Using "cat /bin" is a poor example, because everybody KNOWS /bin is a
    directory. But how about using a more realistic example? Say, "cat
    /usr/libexec/sendmail"? That happens to be a directory, but could easily be
    mistaken for a regular file (when found in a find output, for instance). And
    then a lot of crap scrolls through your terminal, which is potentially
    DANGEROUS. Just because you cannot fathom a legitimate situation in which a
    cat on a directory was unexpected and unintentional, does not mean that
    situation never occurs.

    I would like to see a switch added to cat, like "-d", which specifically
    allows it to operate on directories too, for that once-in-a-million chance I
    actually need a hex dump on the directory as file. In fact, that behavior is
    already incorporated in the "rm" command:

    The options are as follows:

      -d Attempt to remove directories as well as other types of files.

    So, in like fashion for "cat":

      -d Attempt to write the raw contents of a directory too.

    - Mark

    _______________________________________________
    freebsd-questions@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-questions
    To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"


  • Next message: Micheal Patterson: "Re: FreeBSD and SMP support"

    Relevant Pages

    • Re: Re:Re: Cat a directory
      ... in UNIX pretty much everything is considered a file. ... Say, "cat ... > mistaken for a regular file ... Just because you cannot fathom a legitimate situation in which a ...
      (freebsd-questions)
    • Re: (no subject)
      ... depends, if /dev/null does not exist before the cat, ... it will be created as regular file, residing on the ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)