cat: No, not the feline

I’ll just mention coreutil’s cat very quickly, because it’s one of those omnipresent tools that everyone uses almost daily. I like to think it’s the first console tool people learn.


In spite of that, there are right ways and wrong ways to use it. The Internet is full of examples of misuses of cat, and what the right way should be.

cat really only does one thing: takes the contents of a file and directs it to the screen.

The beauty of it though, is when it’s used in combination with redirects, double redirects and so forth.

So it can function as a primitive copy tool, just by

cat oldtext.txt > newtext.txt

or tack one file on the end of another:

cat oldtext.txt >> newtext.txt

Dump text into a file from the keyboard with:

cat - > textfile.txt

The possibilities are endless, really. And maybe you didn’t know it, but cat does have a few flags you can use. Flag of the day is:

cat -n textfile.txt

which numbers the lines. Clever, eh?

If you want a better introduction, may I suggest this page, which has a quite a few nifty examples of what to do with cat.

Now then. Let’s move on, shall we?

P.S., rumor has it you can concatenate some audio or video files with cat. Who’d’ve thunk it?! :mrgreen:

15 thoughts on “cat: No, not the feline

  1. Ian Munsie

    I’m surprised you didn’t mention that cat can be used to concatenate two or more files together (hence the name), e.g.
    cat file1.txt file2.txt file3.txt > combined.txt

  2. Pingback: csplit: split, but with a little more control | Inconsolation

  3. Pingback: cwp: Not the feline, but with progress | Inconsolation

  4. Pingback: fold: Pretty simple, pretty cool | Inconsolation

  5. Pingback: hoz: Speedy, but with quirks | Inconsolation

  6. Pingback: pv: Why won’t you talk to me? | Inconsolation

  7. Pingback: tac: Not tic- or -toe either | Inconsolation

  8. Pingback: tcat: Just quickly, because it’s fun | Inconsolation

  9. Pingback: tee: More magic from coreutils | Inconsolation

  10. Pingback: lolcat: From the ears to the eyes | Inconsolation

  11. Pingback: fselect: Pulled from the brink | Inconsolation

  12. Pingback: shpaint: For the Toulouse-Lautrec of the terminal | Inconsolation

  13. Pingback: shpaint: For the Toulouse-Lautrec of the terminal | Linux Admins

Comments are closed.