What is the main purpose of the less command in Linux?
The less command lets you view text files one screen at a time. It allows you to scroll forward and backward through the file easily.
Click to reveal answer
beginner
How does more differ from less in terms of navigation?
more only allows forward navigation through a file, while less lets you move both forward and backward.
Click to reveal answer
beginner
Which key do you press to quit less or more?
Press the q key to quit and exit the less or more viewer.
Click to reveal answer
intermediate
How can you search for a word inside a file when using less?
Type / followed by the word you want to find, then press Enter. Use n to go to the next match.
Click to reveal answer
intermediate
What happens if you run cat filename | less?
It sends the output of cat filename into less, letting you view the file page by page instead of all at once.
Click to reveal answer
Which command allows backward scrolling through a file?
Acat
Bless
Cmore
Dhead
✗ Incorrect
less supports both forward and backward scrolling, unlike more.
What key do you press to exit more or less?
Ae
Bx
Cq
DCtrl+C
✗ Incorrect
Pressing q cleanly exits the pager.
How do you search for a word inside less?
AType #word
BType :search word
CType ?word and press Enter
DType /word and press Enter
✗ Incorrect
Typing /word starts a forward search in less.
Which command only allows forward scrolling?
Amore
Bhead
Ctail
Dless
✗ Incorrect
more only supports forward scrolling.
What does cat file | less do?
ASends file content to less for paginated viewing
BDisplays the file all at once
CEdits the file
DDeletes the file
✗ Incorrect
It pipes the file content into less for easy reading.
Explain how you would use less to view a long log file and search for a specific error message.
Think about opening, searching, navigating, and exiting.
You got /4 concepts.
Describe the differences between less and more commands and when you might prefer one over the other.
Focus on navigation and features.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the less command in Linux?
easy
A. To delete files from the system
B. To edit text files directly in the terminal
C. To compile source code files
D. To view long text files one page at a time with easy scrolling
Solution
Step 1: Understand the function of less
less is a pager program used to view text files or command output one page at a time.
Step 2: Compare with other options
Options A, B, and D describe deleting, editing, and compiling, which are not functions of less.
Final Answer:
To view long text files one page at a time with easy scrolling -> Option D
Quick Check:
less = paginated viewing [OK]
Hint: Remember: less lets you scroll up and down easily [OK]
Common Mistakes:
Confusing less with text editors like vi
Thinking less edits files
Assuming less deletes files
2. Which of the following is the correct syntax to view a file named log.txt using more?
easy
A. more > log.txt
B. more log.txt <
C. more log.txt
D. more log.txt -f
Solution
Step 1: Recall basic syntax of more
The correct way to view a file is by passing the filename as an argument: more filename.
Step 2: Analyze options
more log.txt < uses incomplete input redirection syntax; more > log.txt uses output redirection which is incorrect; more log.txt -f places option after filename, treating -f as a file.
Final Answer:
more log.txt -> Option C
Quick Check:
Use more filename to view files [OK]
Hint: Use more filename to open files quickly [OK]
Common Mistakes:
Using output redirection instead of input
Adding invalid options to more
Confusing input and output redirection
3. What will be the output when you run the command ls -l /etc | less?
medium
A. Shows the detailed list of /etc directory contents one page at a time with scrolling
B. Shows an error because less cannot be used with pipes
C. Deletes the /etc directory contents
D. Lists the contents of /etc directory all at once without paging
Solution
Step 1: Understand the command pipeline
ls -l /etc lists detailed contents of /etc. The pipe | sends this output to less.
Step 2: Effect of less on piped output
less paginates the output, allowing scrolling through the list one page at a time.
Final Answer:
Shows the detailed list of /etc directory contents one page at a time with scrolling -> Option A
Quick Check:
Piping to less = paginated output [OK]
Hint: Pipe output to less to scroll long lists easily [OK]
Common Mistakes:
Thinking less deletes files
Assuming less shows all output at once
Believing less cannot be used with pipes
4. You run more file.txt but the command exits immediately without showing the file content. What is the most likely reason?
medium
A. The file file.txt is empty
B. You typed more incorrectly
C. The terminal does not support paging
D. The file file.txt is a directory
Solution
Step 1: Consider what happens with an empty file
If file.txt is empty, more has no content to display and exits immediately.
Step 2: Evaluate other options
Typing errors would cause command not found or syntax errors; terminal support is rarely an issue; if file.txt is a directory, more would show an error.
Final Answer:
The file file.txt is empty -> Option A
Quick Check:
Empty file = no output from more [OK]
Hint: Empty files cause more to exit immediately [OK]
Common Mistakes:
Assuming more always shows something
Not checking if file is empty
Confusing file with directory
5. You want to view a log file system.log but also want to search inside it while scrolling. Which command is best to use?
hard
A. more system.log
B. less system.log
C. cat system.log
D. head system.log
Solution
Step 1: Identify commands that allow searching while viewing
less supports searching inside the file while scrolling up and down.
Step 2: Compare with other commands
cat shows all content at once; more allows paging but limited searching; head shows only the first lines.
Final Answer:
less system.log -> Option B
Quick Check:
Use less for scrolling and searching [OK]
Hint: Use less to scroll and search inside files [OK]
Common Mistakes:
Using cat for long files
Choosing more which has limited search
Using head which shows only start
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.