ahh

~$ which cat
you are viewing a single comment's thread
view the rest of the comments
[–] 85 points 3 months ago* (22 children)

cat is misunderstood a lot. The purpose of cat is to combine multiple files together (it's literally short for "concatenate"), like cat *.log to combine all log files together.

If you're just using it for a single file, then you should just redirect the file to stdin. These two command lines behave similarly:

cat foo.txt | some-command
some-command < foo.txt

For head, tail, grep and some other commands, you can just pass in the file name directly as an argument (e.g. grep whatever foo.txt).

  • source
  • hideshow 22 child comments
  • [–] 70 points 3 months ago (4 children)
  • [–] [S] 17 points 3 months ago (3 children)

    awww what's a cat without a head and a tail?

  • source
  • parent
  • hideshow 3 child comments
  • [–] [S] 16 points 3 months ago (4 children)

    yeah sure but the command is literally written for the humor.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 19 points 3 months ago (3 children)

    I know, but I just wanted to mention this since a lot of new Linux users end up using cat this way :)

  • source
  • parent
  • hideshow 3 child comments
  • [–] 10 points 3 months ago (2 children)

    I still like doing cat file.txt | grep thing because I often re-run it to find something else like cat file.txt | grep thing2 - and if I do that with grep, the pattern sits awkwardly in the middle instead of at the end

  • source
  • parent
  • hideshow 2 child comments
  • [–] 11 points 3 months ago (6 children)

    Fair, but in general I find it way more useful to use cat for piping.

    In most cases I'll do something like

    cat file | program
    cat file | program | grep
    cat file | program | grep | cut
    

    This gets more complicated if the file is at the end of the command.

  • source
  • parent
  • hideshow 6 child comments
  • [–] 9 points 3 months ago (4 children)

    It wouldn't be at the end, since you'd still be piping into program

    program <file | grep | cut
    
  • source
  • parent
  • hideshow 4 child comments