How To Read A Text File On A Linux Server Using SSH
To read a text file in a Linux SSH terminal, users have several command-line tools available, each suited for different needs.
The simplest command is cat
one that outputs the entire file content to the terminal.
It’s best suited for small files that fit within a single screen. For larger files, it less
is a more practical option.
It opens the file in a scrollable interface, allowing navigation with the arrow keys and quitting with the q
key.
Another command also displays the file one screen at a time, though with fewer navigation features than less
.
For quick previews, it head
shows the first few lines of a file (default is 10), while it tail
shows the last few lines.
These can be extended -n
to display a custom number of lines.
Additionally, tail -f
is useful for real-time monitoring, such as watching logs as they update.
These commands are essential for developers, system administrators, and anyone managing Linux servers remotely via SSH.
They provide fast and flexible access to file contents directly from the terminal without needing a graphical interface, making them indispensable tools in Unix-based environments.
📖 Basic Commands to Read a File In Linux Via SSH
cat
– View the whole file at once
cat filename.txt
- Best for small files.
- Displays the entire content at once.
less
– Scrollable viewer (best for large files)
less filename.txt
- Use the arrow keys or Page Up/Page Down to scroll.
- Press
q
to quit.
more
– Scroll by screen (simpler than less
)
more filename.txt
- Press Enter for the next line, Space for the next page.
- Press
q
to quit.
head
– View the first few lines
head filename.txt
- Shows the first 10 lines by default.
head -n 20 filename.txt # Show first 20 lines
tail
– View the last few lines
tail filename.txt
- Shows the last 10 lines by default.
tail -n 20 filename.txt # Show last 20 lines
Bonus: Follow a file live (like a log file)
tail -f filename.txt
- Useful for monitoring log files in real-time.
✅ Example Use:
cd /var/log
less syslog
When you’re done reading the file.
If you’re using:
-
less
ormore
: Pressq
to quit. -
cat
,head
, ortail
: These exit automatically after displaying the content.
How All Pro Web Designs Can Help!
Empower your business with cutting-edge web solutions!
From custom development and responsive design to SEO and e-commerce, our services will enhance performance, security, and user experience.
Don’t fall behind—optimize, scale, and innovate with the most in-demand web development trends today.
Request a quote today!
Leave a Reply