Paging Through Files (less)
The less command lets you page through files one screen at a time. It's perfect for reading large files.
Basic Usage
less filename
Why "less"?
The name comes from the phrase "less is more" - less is an improved version of an older command called more.
Navigation in less
| Key | Action |
|---|---|
Space / f | Forward one page |
b | Back one page |
d | Forward half page |
u | Back half page |
g | Go to beginning |
G | Go to end |
q | Quit |
Searching in less
| Key | Action |
|---|---|
/pattern | Search forward |
?pattern | Search backward |
n | Next match |
N | Previous match |
Example:
- Open file with
less file.txt - Type
/errorto search for "error" - Press
nto find next occurrence
less Options
| Option | Description |
|---|---|
-N | Show line numbers |
-S | Chop long lines (no wrap) |
-i | Case-insensitive search |
-F | Quit if file fits on screen |
+G | Start at end of file |
Exercise: Page Through a File
Use less to view a log file:
less vs cat vs more
| Feature | cat | more | less |
|---|---|---|---|
| Scroll back | No | No | Yes |
| Search | No | Limited | Yes |
| Large files | Bad | OK | Best |
| Navigation | None | Forward | Both |
Useful less Commands
Line Numbers
less -N file.txt
Follow File (like tail -f)
less +F /var/log/syslog
Start at Pattern
less +/error logfile.txt
Multiple Files
less file1.txt file2.txt
# :n - next file
# :p - previous file
Viewing Piped Output
cat /var/log/*.log | less
history | less
ps aux | less
Common Patterns
View Logs
less /var/log/syslog
less -N +G /var/log/auth.log # With line numbers, at end
Read Documentation
man ls | less # Actually uses less
Key Takeaways
lessis ideal for viewing large files- Navigate with Space, b, g, G
- Search with
/pattern - Press
qto quit - Better than
catfor anything over one screen
التالي · الدرس 15 من 40
Head and Tail
قراءة 2 دقيقة
أنهيت 14 من 40 درسًا

اسأل Byte عن هذا الدرس
محادثة خاصة حول هذا الدرس. قرأ Byte الدرس كاملًا، ويجيب خلال ثوانٍ، ويُظهر القسم الذي تأتي منه كل إجابة. يمكنك السؤال بأي لغة.
الأسئلة والأجوبة
أسئلة عامة حول هذا الدرس. يجيب AI Tutor فورًا بلغتك، ويراجع فريق FreeAcademy الإجابات، ويمكن لكل المتعلمين قراءتها.

