Bird
Raised Fist0
Linux CLIscripting~20 mins

less and more (paginated viewing) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Pager Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of 'less' command with a specific key press
You run less on a text file with 100 lines. After opening, you press the spacebar key once. What happens?
Linux CLI
less sample.txt
AThe display moves forward by one line only.
BThe display moves forward by one full screen of lines.
CThe display moves backward by one full screen of lines.
DThe display exits immediately.
Attempts:
2 left
💡 Hint
Think about how 'less' paginates content and what the spacebar does.
💻 Command Output
intermediate
2:00remaining
Behavior of 'more' when reaching end of file
You use the command more sample.txt to view a file. When you reach the end of the file, what does 'more' do?
Linux CLI
more sample.txt
AIt automatically exits and returns to the shell prompt.
BIt waits for user input to scroll further even though no more lines exist.
CIt loops back to the start of the file.
DIt displays an error message and exits.
Attempts:
2 left
💡 Hint
Consider what happens when you reach the end of content in pagers.
📝 Syntax
advanced
2:00remaining
Correct command to search forward in 'less'
Which command inside 'less' allows you to search forward for the word 'error'?
Linux CLI
less /var/log/syslog
A?error
B#error
C:error
D/error
Attempts:
2 left
💡 Hint
Think about how forward and backward searches differ in 'less'.
💻 Command Output
advanced
2:00remaining
Output of 'more' with piped input
You run the command cat file.txt | more. What is the behavior of 'more' in this case?
Linux CLI
cat file.txt | more
A'more' ignores the input and exits immediately.
B'more' outputs the entire content without pagination.
C'more' paginates the output, allowing scrolling page by page.
D'more' waits for a filename argument and shows an error.
Attempts:
2 left
💡 Hint
Consider how 'more' handles standard input from pipes.
🚀 Application
expert
3:00remaining
Combining 'less' with environment variable for default options
You want 'less' to always start with line numbers shown and ignore case in searches. Which environment variable setting achieves this?
Aexport LESS='-N -i'
Bexport LESS='-n -I'
Cexport LESS='-N -I'
Dexport LESS='-n -i'
Attempts:
2 left
💡 Hint
Check 'less' man page for option meanings: -N shows line numbers, -i ignores case.

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

  1. 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.
  2. Step 2: Compare with other options

    Options A, B, and D describe deleting, editing, and compiling, which are not functions of less.
  3. Final Answer:

    To view long text files one page at a time with easy scrolling -> Option D
  4. 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

  1. Step 1: Recall basic syntax of more

    The correct way to view a file is by passing the filename as an argument: more filename.
  2. 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.
  3. Final Answer:

    more log.txt -> Option C
  4. 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

  1. Step 1: Understand the command pipeline

    ls -l /etc lists detailed contents of /etc. The pipe | sends this output to less.
  2. Step 2: Effect of less on piped output

    less paginates the output, allowing scrolling through the list one page at a time.
  3. Final Answer:

    Shows the detailed list of /etc directory contents one page at a time with scrolling -> Option A
  4. 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

  1. Step 1: Consider what happens with an empty file

    If file.txt is empty, more has no content to display and exits immediately.
  2. 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.
  3. Final Answer:

    The file file.txt is empty -> Option A
  4. 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

  1. Step 1: Identify commands that allow searching while viewing

    less supports searching inside the file while scrolling up and down.
  2. Step 2: Compare with other commands

    cat shows all content at once; more allows paging but limited searching; head shows only the first lines.
  3. Final Answer:

    less system.log -> Option B
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard