Prerequisites
Before viewing file contents, make sure you have:
- SSH access to your VPS
- Read permissions for the file
Method 1: Using cat (Full File Content)
Connect to your VPS:
ssh hxroot@YOUR_SERVER_IP -p 22
Display entire file:
cat filename.txt
Display multiple files:
cat file1.txt file2.txt
Show line numbers:
cat -n filename.txt
Show with $ at end of lines:
cat -e filename.txt
Method 2: Using less (Paged View)
View file page by page:
less filename.txt
Navigation in less:
- Space/Page Down - Next page
- b/Page Up - Previous page
- d - Half page down
- u - Half page up
- /pattern - Search forward
- ?pattern - Search backward
- n - Next match
- N - Previous match
- g - Go to start of file
- G - Go to end of file
- q - Quit
View file with line numbers:
less -N filename.txt
Method 3: Using more (Simple Pager)
more filename.txt
Navigation in more:
- Space - Next page
- Enter - Next line
- b - Previous page
- /pattern - Search
- q - Quit
Method 4: Using head (Beginning of File)
Show first 10 lines (default):
head filename.txt
Show first 20 lines:
head -20 filename.txt
Show all except last 5 lines:
head -n -5 filename.txt
Method 5: Using tail (End of File)
Show last 10 lines (default):
tail filename.txt
Show last 20 lines:
tail -20 filename.txt
Show all except first 5 lines:
tail -n +5 filename.txt
Follow file in real-time (logs):
tail -f /var/log/syslog
Follow with filtering:
tail -f /var/log/syslog | grep error
Method 6: Using nl (Numbered Lines)
nl filename.txt
Same as cat -n but skips blank lines.
Method 7: Using tac (Reverse Order)
Show file with lines in reverse order:
tac filename.txt
Method 8: View Specific Lines with sed
Show line 5:
sed -n '5p' filename.txt
Show lines 10-20:
sed -n '10,20p' filename.txt
Method 9: Search Inside File Before Viewing
Show lines containing pattern:
grep "error" filename.txt
Show with line numbers:
grep -n "error" filename.txt
Show context around pattern:
grep -C 5 "error" filename.txt
Method 10: View Binary Files
View hex dump:
hexdump -C file.bin
View file type:
file filename.txt
Quick Reference Table
| Command | Use Case |
|---|---|
cat file | Small files, entire content |
less file | Large files, interactive navigation |
head -20 file | View beginning of file |
tail -20 file | View end of file |
tail -f file | Monitor real-time logs |
grep pattern file | Search within files |
Practical Examples
Check SSH logs quickly:
tail -100 /var/log/auth.log | grep "Accepted"
View configuration without editing:
less /etc/nginx/nginx.conf
Monitor web server access log:
tail -f /var/log/nginx/access.log
Check first few lines of large SQL dump:
head -100 database.sql
View last 50 lines of error log:
tail -50 /var/log/php_errors.log
Combine Multiple Commands
View file with grep and less:
grep "error" /var/log/syslog | less
View unique lines:
sort filename.txt | uniq | less
✅ You can now view file contents without opening a text editor on your Hostxpeed VPS.