Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Three Cats (thenewsh.blogspot.com)
44 points by tptacek on March 26, 2010 | hide | past | favorite | 15 comments


Point: Bloat in cat is bad and un-UNIXy, cf. http://harmful.cat-v.org/cat-v/

Counter-point: If cat is becoming your performance bottleneck, you're doing it wrong: http://sial.org/howto/shell/useless-cat/

Yes, the GNU version looks dreadful, but I think that really doesn't matter that much.

EDIT: Well, I guess I didn't consider the case where you want to put cat in a chroot jail. On Solaris 10:

$ ldd /usr/bin/cat

    libc.so.1 =>         /lib/libc.so.1
    libm.so.2 =>         /lib/libm.so.2
    /platform/SUNW,T5240/lib/libc_psr.so.1
$ ldd /usr/gnu/coreutils/default/bin/cat

    libnsl.so.1 =>       /lib/libnsl.so.1
    libc.so.1 =>         /lib/libc.so.1
    libmp.so.2 =>        /lib/libmp.so.2
    libmd.so.1 =>        /lib/libmd.so.1
    libscf.so.1 =>       /lib/libscf.so.1
    libdoor.so.1 =>      /lib/libdoor.so.1
    libuutil.so.1 =>     /lib/libuutil.so.1
    libgen.so.1 =>       /lib/libgen.so.1
    libm.so.2 =>         /lib/libm.so.2
    /platform/SUNW,T5240/lib/libc_psr.so.1
    /platform/SUNW,T5240/lib/libmd_psr.so.1
Yikes...


    [rupert] ~$ ldd $(which cat)
            libintl.so.3 =>  /lib/libintl.so.3
            libiconv.so.2 =>         /lib/libiconv.so.2
            libc.so.1 =>     /lib/libc.so.1
            libsocket.so.1 =>        /lib/libsocket.so.1
            libgcc_s.so.1 =>         /lib/libgcc_s.so.1
            libsec.so.1 =>   /lib/libsec.so.1
            libnsl.so.1 =>   /lib/libnsl.so.1
            libavl.so.1 =>   /lib/libavl.so.1
            libidmap.so.1 =>         /usr/lib/libidmap.so.1
            libmp.so.2 =>    /lib/libmp.so.2
            libmd.so.1 =>    /lib/libmd.so.1
            libscf.so.1 =>   /lib/libscf.so.1
            libldap.so.5 =>  /usr/lib/libldap.so.5
            libresolv.so.2 =>        /lib/libresolv.so.2
            libsldap.so.1 =>         /usr/lib/libsldap.so.1
            libuutil.so.1 =>         /lib/libuutil.so.1
            libgen.so.1 =>   /lib/libgen.so.1
            libsasl.so.1 =>  /usr/lib/libsasl.so.1
            libnspr4.so =>   /usr/lib/libnspr4.so
            libplc4.so =>    /usr/lib/libplc4.so
            libnss3.so =>    /usr/lib/libnss3.so
            libssl3.so =>    /usr/lib/libssl3.so
            librt.so.1 =>    /lib/librt.so.1
            libdl.so.1 =>    /lib/libdl.so.1
            libsoftokn3.so =>        /usr/lib/libsoftokn3.so
            libplds4.so =>   /usr/lib/libplds4.so
            libm.so.2 =>     /lib/libm.so.2
(Nexenta NCP 2.0; there's a simpler cat in /usr/sun/bin.)


On Mac OS 10.6:

  $ otool -L /bin/cat
  /bin/cat:
  	/usr/lib/libSystem.B.dylib
  
  $ otool -L /usr/lib/libSystem.B.dylib 
  /usr/lib/libSystem.B.dylib:
  	/usr/lib/libSystem.B.dylib
  	/usr/lib/system/libmathCommon.A.dylib
  
  $ otool -L /usr/lib/system/libmathCommon.A.dylib
  /usr/lib/system/libmathCommon.A.dylib:
  	/usr/lib/system/libmathCommon.A.dylib


Not sure what's wrong with Solaris. Linux is much more sane:

    $ ldd /bin/cat 
            linux-vdso.so.1 =>  (0x00007ffff71ff000)
            libc.so.6 => /lib/libc.so.6 (0x00007f5ef56ec000)
            /lib64/ld-linux-x86-64.so.2 (0x00007f5ef5a71000)


My favorite is true: http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f...

Solaris used to have one that was a shell script that contained only copyright header comments and no code. The current OpenSolaris one looks sane: http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/sr...


I loved the comments in the GNU cat.

"Why are (OUTSIZE - 1 + INSIZE * 4 + LINE_COUNTER_BUF_LEN + PAGE_SIZE - 1) bytes allocated for the output buffer?"

Then it goes on a 15 lines article, divided in two paragraphs, explaining the reasoning behind the code.


Yeah ... I enjoyed "An 11 digit counter may overflow within an hour on a P2/466", too. GNU obviously overclock their hardware, the Wikipedia page for the Pentium II says it topped out at 450 MHz, in 1999.


   cat --vet
The gnu cat comes with it's own vet ;-)

I actually use this feature and am grateful for it's existence.


Out of curiosity, what exactly do you use it for? Couldn't matching on newline accomplish the same end?


Most common use is to find control characters in a file where they shouldn't be.


I think you want just one dash (?).


yea and the v is redundant, or you could just do -A.


I think you mean cat -vet


The GNU version might look intimidating, but I think that's just the code style getting in the way. I'm betting that, compiled to assembler, it doesn't consist of many more tokens than the first version. (Anyone care to test? Don't have a toolchain in front of me at the moment.)


One of them gives Tim an aneurysm. CAN YOU GUESS WHICH?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: