Table of Contents
- Introduction
- What Are These Commands?
- Real-World Scenario: Using File Viewing Commands
- Conclusion
- Let's Connect
Introduction
Welcome back to day 19!.Today’s focus is on file-viewing commands:
cat
, less
, more
, head
, and tail
.
When working with files in Linux, being able to view logs, outputs, and configuration files quickly is critical. You don’t always need to open a full editor like vim
, sometimes a simple peek is all you need.
Let’s get into it!
What Are These Commands?
Command | Purpose |
---|---|
cat |
Concatenate and display file contents |
less |
View file one page at a time, scrollable |
more |
Similar to less, but can only scroll forward |
head |
Show the first few lines of a file |
tail |
Show the last few lines of a file (often logs) |
Real-World Scenario: Using File Viewing Commands
You work as a Junior Linux Admin. Your team gives you a log file and says:
- Let's view the file using
cat
man man > manualpage.txt - # we created a file called manual page by opening the man command and copying the contents into manualpage.txt
cat manualpage.txt # this views the file showing what we created.
- Let's check the
man
page, and usemore
to view the content page by page. Note, you can only scroll forward. ( The up and arrow keys works, but forward and backward here means using the right and left arrow keys.)
more manualpage.txt
- Let's view a large file or logs using
less
. This helps you view large files page by page, and you can scroll forward and backward unlike themore
command.
less manualpage.txt
- We use
head
to view the top lines of the files. You can include the number of lines you also intend to view.
head manualpage.txt
or
head -n 5 manualpage.txt to view the first 5 lines.
- You can also view the last lines using
tail
command.
tail manualpage.txt
or
tail -5 manualpage.txt to view the last 5 lines.
Conclusion
These file viewing commands are very essential, and by mastering these commands, even a beginner can:
Quickly read and understand system logs
Debug issues like failed logins or service restarts
Monitor live updates without extra tools
If this is helpful to you, feel free to bookmark, comment, like and follow me for Day 20!
Let's Connect!
If you want to connect or share your journey, feel free to reach out on LinkedIn.
I am always happy to learn and build with others in the tech space.
#30DaysLinuxChallenge #Redhat#RHCSA #RHCE #CloudWhistler #Linux #Rhel #Ansible #Vim #CloudComputing #DevOps #LinuxAutomation #IaC #SysAdmin#CloudEngineer