When you are managing a Linux server through a terminal, you don’t have a graphical text editor like Notepad or Gedit to simply double-click and open files. You must read text files directly within the command line interface. The most common, fundamental tool for reading short configuration files, scripts, or logs in Ubuntu Linux is the cat command.
What Does the cat Command Do?
The name cat stands for “concatenate.” While its original purpose was to link multiple files together, its primary everyday use is simply to print the contents of a file directly onto your terminal screen. It takes the text inside the file and forcefully spits it out onto your display.
How to View a Single File
To read a file, you simply type cat followed by a space, and then the name of the file you want to read.
cat system_config.txt
As soon as you press Enter, the entire contents of system_config.txt will instantly print onto the screen. Once it reaches the end of the file, your normal terminal prompt will reappear, ready for the next command.
How to View Multiple Files at Once
Because “concatenate” means to link together, you can feed the cat command multiple files at the same time. It will read the first file, print it to the screen, and then immediately print the second file right underneath it, effectively combining them visually.
cat part1.txt part2.txt
This is extremely useful when reading log files that have been split into separate chunks by the system.
Adding Line Numbers to the Output
If you are reading a bash script or a configuration file to troubleshoot an error, the system will often tell you “Syntax error on line 42.” By default, cat just prints raw text without numbers. You can force cat to display line numbers by adding the -n flag (number).
cat -n network_settings.conf
The output will now feature a numbered column on the left side, making it much easier to locate specific lines of code.
The Limitation of cat: Long Files
The cat command is a “dumb” printer. If you use it on a tiny 5-line file, it works perfectly. However, if you use cat on a massive system log file containing 10,000 lines, it will instantly dump all 10,000 lines onto the screen. The text will fly by in a blur, and you will only be left staring at the very last page of the document.
If a file is too long to fit on a single screen, you should not use cat. Instead, you should use the less command (e.g., less system.log), which allows you to scroll through the document page-by-page using the arrow keys.