The Data Interrogation Vector
When administering a headless Ubuntu server, you will frequently need to quickly verify the contents of a configuration file, check a public SSH key, or read a short log file. While you could open the file in a full text editor like nano or vim, this is highly inefficient if you simply want to read the data without making any modifications. You need a method to rapidly dump the file’s contents directly to the terminal screen.
How to View the Contents of a File
The Linux ecosystem provides two distinct utilities for this task, depending entirely on the physical size of the file you are attempting to read.
1. Open your terminal application or connect to your server via SSH.
2. For short files (The `cat` command): If the file is only a few lines long (like an SSH key or a basic network config), you want to concatenate the output directly to the screen.
* Type cat followed by the filename (e.g., cat /etc/hostname).
* Press Enter. The entire text will instantly print to the terminal, and you will be immediately returned to the command prompt.
3. For long files (The `less` command): If the file is massive (like a system log containing thousands of lines), using `cat` will cause the text to violently scroll past you in a blur. You must use a “pager” utility to view it one screen at a time.
* Type less followed by the filename (e.g., less /var/log/syslog).
* Press Enter. The terminal will clear, displaying only the first page of the file.
* Use the Up/Down Arrow keys to scroll line by line, or the Spacebar to jump down an entire page.
* When you are finished reading, you must press the Q key to quit the pager and return to the normal bash prompt.