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?!
I think you could omit the dash in “cat – > textfile.txt”
Yep, it works. Odd, I never tried it without the dash. Thanks! 😉
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
Pingback: csplit: split, but with a little more control | Inconsolation
Pingback: cwp: Not the feline, but with progress | Inconsolation
Pingback: fold: Pretty simple, pretty cool | Inconsolation
Pingback: hoz: Speedy, but with quirks | Inconsolation
Pingback: pv: Why won’t you talk to me? | Inconsolation
Pingback: tac: Not tic- or -toe either | Inconsolation
Pingback: tcat: Just quickly, because it’s fun | Inconsolation
Pingback: tee: More magic from coreutils | Inconsolation
Pingback: lolcat: From the ears to the eyes | Inconsolation
Pingback: fselect: Pulled from the brink | Inconsolation
Pingback: shpaint: For the Toulouse-Lautrec of the terminal | Inconsolation
Pingback: shpaint: For the Toulouse-Lautrec of the terminal | Linux Admins