The Output Vector
When operating a headless Ubuntu Linux server, you will frequently need to quickly inspect the contents of a configuration file, a bash script, or an error log. Launching a full terminal-based text editor (such as Nano or Vim) just to read a few lines of text is inefficient and risks accidental modification of critical system files. Administrators require tools that simply output the text directly to the screen for rapid review.
How to View File Contents in the Terminal
Linux provides several native utilities for reading text files, each suited to a different length of document.
1. Open your terminal application or connect to your server via SSH.
2. For short files: Use the cat (concatenate) command. This instantly dumps the entire contents of the file into your terminal output. For example, to read your network hosts file, execute:
cat /etc/hosts
3. For massive files (like system logs): If you use cat on a massive log file, it will rapidly scroll past your screen. Instead, use the less command, which opens a dedicated viewing environment allowing you to scroll through the file at your own pace:
less /var/log/syslog
While inside the less viewer, you can use the up and down arrow keys to navigate. To search for a specific word, type a forward slash (/), type your word, and press Enter. When you are finished reading, press the Q key to immediately exit back to the standard terminal prompt.