These commands allow you to read and analyze the contents of text files.
-
cat file.txt→ Displays the entire content offile.txtdirectly in the terminal. This is suitable for smaller files. -
less longfile.txt→ Openslongfile.txtin a scrollable viewer. You can navigate through the file using the arrow keys, Page Up, Page Down, and quit by pressingq. This is useful for large files. -
head -10 file.txt→ Shows the first 10 lines offile.txt. You can replace10with any number to display a different number of lines. -
tail -10 file.txt→ Shows the last 10 lines offile.txt. Similar tohead, you can change the number of lines displayed.tail -f file.txtis particularly useful for monitoring log files in real-time as new lines are added.
Display the Linux distribution information and the first 5 lines of the system log file:
cat /etc/os-release
head -5 /var/log/syslog