Jason Turley's Website

cat is the best text editor

Every Linux user knows they can use cat to print out the contents of a file. But not many know they can use cat to directly edit a file.

Start by entering:

$ cat > lol.txt

The program will hang, waiting for you to type something.

$ cat > lol.txt
This file was created using cat (^._.^)
Hit Ctrl+D to exit!

Note that lol.txt will be completely overwritten if it already exists.

Thus, cat can be used as a text editor! Never again will you have to toil with confusing vim commands, sluggish IDEs, or get made fun of for using nano.

Still not convinced? Here’s three (3) reasons why cat is the perfect text editor!


compact!

The cat binary is small. Just like a kitten.

See how its size compares to the popular text editors vim and nano:

$ size /usr/bin/cat /usr/bin/vim /usr/bin/nano
   text    data     bss     dec     hex filename
  31151    1568     408   33127    8167 /usr/bin/cat
2723805  170360   56912 2951077  2d07a5 /usr/bin/vim
304637    6002    2240  312879   4c62f  /usr/bin/nano

As we can see, the cat binary is much smaller than vim and nano.

fast!

Fancy GUIs like Visual Studio and Atom take forever to boot because of all the plugins and libraries bundled with them.

However, cat is fast! Look how quickly it prints this random header file:

$ ls -l /usr/include/netdb.h 
-rw-r--r-- 1 root root 28100 Jul  6 15:16 /usr/include/netdb.h

$ time cat /usr/include/netdb.h
...

real    0m0.016s
user    0m0.001s
sys     0m0.004s

everywhere!

No need to install a fancy text editor on each new system you use. cat is a built in command on all UNIX distros!

FAQ

How can I edit existing code without completely overwriting?

You can’t and shouldn’t need to. You’re a programmer, therefore your code always works as expected the first time :)

What about syntax highlighting?

There isn’t any! All the pretty colors will distract you from coding well.

But what if I want to write my files in reverse?

Use tac.

Why did you make this blog?

Because the world needs to know that cat is the best text editor.

Is that the real reason?

Nope. I thought it was a neat, albeit unpractical way to make files.

Is cat really your text editor of choice?

No, that honor goes to vim. But I do like using cat to create small files from time to time.

#linux #personal