Today's article is really a beginner's type of article...

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
11,819
Reaction score
10,388
Credits
97,767
There are commands that you can do quite a bit with. I didn't want to give too much away, because I think there's some discovery to be had by the end user - that is thinking of the different things you can do with the command.

So, today we have just a brief overview of the cat command. It's nothing fancy and there's a lot that you can do with the command.


If you've used the cat command before, there's not much to this article. It's a weekend and I figured this would be an easy enough article for folks - including me.
 


The cat command is one of linux's everlasting and ongoing discussion points. It arouses emotions ranging across the whole spectrum from love to disdain. I'm at the lovers end. I recall reading Linus saying something like that you could write a linux kernel with cat. It's that deep.

The "great controversies" can be viewed with a search for the terms "useless use of cat", and there's quite a bit that turns up. In the past I was upbraided for using the command: "cat filename | less". The reproacher asked derisively, why not simply: "less filename", so fewer resources would be used by the computer. Unfortunately, finger memory still jumps to writing "cat" when wanting to snap open a file, rather than less, but the point was taken.

Another often made complaint is that cat is unnecessary for writing a new file, just use >, that is, "> filename" accomplishes the same outcome as "cat > filename". The redirect is quicker it's said, but do the thousandths of seconds matter? It does saves finger presses on the keyboard.

The article mentions how to create an empty file, however, doesn't quite get into using cat to write a file, though it has a heading '"Write Text To A File From The Terminal with ">' and ">>"'. There are instructions to create a new file with "cat > <new_file> &", but none for writing of the file itself, thus not fulfilling the promise of the heading. Actual writing the file, which doesn't need a test editor other than cat and the terminal itself e.g.: "cat > filename", doesn't appear. However, with this command, cat will enable the user to write the file, and then use cntl+d to exit which saves it.

In the olden days, when writing a file with cat, the backspace keys wouldn't erase a character, but rather printed a terminal code in the text, but today, the backspace works as it does anywhere else in the terminal. In this file-writing capacity of cat, the redirect won't do ... if one tries: "> filename", the file is simply emptied, whereas: "cat > filename", will invite the user to write the file. The redirect > can be useful to empty files, but can't replace cat there.

The other major use of cat in the olden days was the transfer of large files. It can still be useful today as shown in the article. Size limitations yesteryear on dial-up and in some programs meant that a large file needed to be cut into sizeable pieces with the split command and then reformed at the the receiving end with cat. The command: "cat file1 file2 > large_file" accomplished the concatenation.
 
Last edited:
However, with this command, cat will enable the user to write the file, and then use cntl+d to exit which saves it.

That was one of the things I'd hoped people would figure out on their own. I wanted to leave a sense of discovery, 'cause the cat command is that immersive. I left plenty of hints, I'd think. I figured it was low hanging fruit and easily figured out on their own.

I was also hoping it'd spark discussion. "I use the cat command to ..."

I figured I'd try something new-ish, which was only giving a light overview but encouraging folks to think of ways to make the cat command useful in their day-to-day lives.
 

Staff online

Members online


Top