Slashdot Mirror


Interview With the Author of "Mastering Cat"

Shlomi Fish writes "O'Reilly is publishing a new book titled 'Mastering cat,' about the UNIX 'cat' command. Here is an interview O'Reilly-Net conducted with the author about it. Read it to see if this book should be part of your bookshelf of technical books."

8 of 243 comments (clear)

  1. Damn. by castorvx · · Score: 5, Informative

    I was hoping for a manual to help me read the icanhascheezburger comments.

    1. Re:Damn. by momerath2003 · · Score: 4, Informative

      That would be "lolcat," not cat. And here is a page to help you.

      --
      I had but a simple dream, to destroy all humans.
  2. I just /usr/bin/cat my coffee everywhere. by Mr.+Flibble · · Score: 2, Informative

    I guess I forgot what day it was, but the title article made me spew my coffee in laughter.

    As an aside, remember kids, don't do this:

    cat foo | grep bar

    It is bad Unix! (If you don't know why, read the non-existent book on cat...) ;)

    --
    Try to hack my 31337 firewall!
    1. Re:I just /usr/bin/cat my coffee everywhere. by steveha · · Score: 5, Informative

      As an aside, remember kids, don't do this:

      cat foo | grep bar

      It is bad Unix!

      Eh, it's not that big a deal.

      Yes, you can simply say "grep bar foo" and it will have the same effect with less typing. But it's really not that big a deal, and there are times when I would do this. Usually it is because I'm doing something like this:

      shell_script foo | grep bar

      And I'm not getting the results I expect; then I might swap out the shell script part for cat, to help me debug. It's easier to type

      cat !*

      or even

      ^shell_script^cat

      than to retype the whole command.

      As long as you know what you are doing, build the command line any way you like. The computer exists to serve you, not the other way around...

      Now someone will mod me (-1, No Sense of Humor) or (-1, Beating the Joke Into the Ground). But I regret nothing! Nothing, I tell you.

      steveha

      --
      lf(1): it's like ls(1) but sorts filenames by extension, tersely
    2. Re:I just /usr/bin/cat my coffee everywhere. by TheRaven64 · · Score: 2, Informative
      The correct general way of doing it (which works for all values of grep) is:

      $ grep bar < foo

      You don't need to do this with grep, since it can take a file as input, but in the general case, any time you are using cat with a single file and a pipe you should be using <.

      It doesn't make much difference when you are running a single command, but it makes a huge difference when you are running a loop or something like a find command. The extra cat doubles the number of fork() and read() system calls, adds a load of unnecessary write()s and adds a lot of copying that is otherwise unneeded.

      --
      I am TheRaven on Soylent News
  3. But seriously by Sloppy · · Score: 2, Informative

    For example, one case where I found that people truly underestimate the power of cat is in the prefixing a line example. You can do that with:
    echo "This would be the first line" | cat - myfile.txt > myfile.txt.new mv -f myfile.txt.new myfile.txt
    But people do not realize that and instead opted to use sed, awk, or even perl (!).

    I've done that.

    --
    As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
  4. Re:How about the followup? by Sir_Lewk · · Score: 3, Informative

    'tac' is an actual *nix program, prints files out in reverse.

    --
    "linux is just DOS with a UNIX like syntax" -- Galactic Dominator (944134)
  5. Re:How about the followup? by palegray.net · · Score: 2, Informative

    for getting [part of] a log file in reverse chronological order

    Funny you should say that, it's exactly how I use the "tac" command.