Post

Stop cat abuse!

Abusing cats is a punishable offense, and a violation of this rule might lead to unquestioned persecution of the offending member

cat-abuse reference

Stop abusing cat!

Abusing cats is a prevalent problem in the Linux user community. Users, ranging from know-nothing neophytes to all-knowing professionals, engage in cat abuse on a daily basis, whether in their scripts or simple terminal commands.

Steps to prevent abuse

  1. Utilize command line arguments instead of cat piping: For example, we generally read the file using cat, and then we pipe the output to input of the other command. Which kinda looks like this
    1
    
    cat file | grep pattern
    

    The above pattern reads the file using cat and then pipes the output as the input for grep. This is a prominent example of cat abuse, where the use of cat is involuntary. The same command can be rewritten as:

    1
    
    grep pattern file
    

    Both of the commands provide the same output but the first command abuses the cat!

  2. File redirection vs cat input: File redirection in Unix-based systems is a more concise and efficient way to leverage file input into commands compared to the age-old method of using cat piping.
    1
    
    cat file1 | command arg1
    
    1
    
    command arg1 < file1 
    

    Though, these two commands culminate in the same output, the second command ensures that cat is not abused!

Places of ignorance

Although, cat abuse is a concerning practice, there are few situtaions where voilation of the rules is acceptable. Like

  • cat piping over multiple redirections
    Consider this command
    1
    
    command < input_file | command2 > out | command3 < input_file
    

    Compared to the above command, the below command is more clear

    1
    
    cat input_file | command1 | command2 > out
    

Reality of cat abuse

In actuality, this is considered UUOC (Useless use of cat). In situations where piping the read file into stdin is unnecessary, it is generally better to avoid it. Doing so only increases the complexity of execution. If the command itself is capable of reading the file, then using cat to read the file and subsequently sending it into stdin is pointless.

Even though the prevelance of cat abuse is quite persistent throughout the Linux user community, many of them do consider it irrelavent and choose to ignore it, as, in reality, it does not affect the day-to-day execution by any means.

Now, we get to ask ourselves a question

Do we abuse the cat or not?

Whether you decide to answer ‘yes’ or ‘no,’ I’ll leave that up to your discretion.

References & Further reading

This post is licensed under CC BY 4.0 by the author.