CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / File Viewing & Editing / more

more

Page through text one screen at a time

Beginnerviewingpagerminimal systems

more shows a file or command output one screenful at a time and waits for a key. It's the original Unix pager: simpler than less, mostly forward-only, and it quits at the end of the file. You'll meet it on minimal systems, rescue shells and BusyBox containers where less isn't installed.

Syntaxmore [OPTION]... FILE... COMMAND | more

Watch it run

You need to read through a log that is longer than your screen on a box with only basic tools.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
more /var/log/app/app.log

One screenful, then the --More-- prompt with how far into the file you are (15%). more is waiting for a key.

Anatomy of a command

$
commandmore

The util-linux pager (BusyBox has its own smaller version).

How it works

more reads the terminal's size with the TIOCGWINSZ ioctl, prints one screen of lines, then puts the terminal into a raw-ish mode so it can read single key presses without Enter, and shows a --More-- prompt with a percentage (for files it knows the size of). Space shows the next screen, Enter the next line, / searches forward with a regular expression, and q quits. Moving backwards (b) only works for files, because a pipe can't be re-read; that limitation is the main reason less was written ('less is more'). When more reaches the end of the input it exits immediately and you're back at the prompt. If standard output is not a terminal (redirected or piped), more doesn't page at all: it behaves like cat, printing a :::::::::::::: header before each file when given several.

Options you'll actually use

Space / EnterNext screen / next line
bBack one screen (files only, not pipes)
/pattern, nSearch forward, repeat search
=Show the current line number
vOpen the file in an editor at the current line
qQuit
+N / +/PATTERNStart at line N / at the first match
-sSqueeze repeated blank lines

Common mistakes

Using more to read a big log you'll need to scroll back through

more only moves forward in pipes and exits at the end, so you can't go back up to an earlier line.

less file (back and forth, search both ways, follow mode)
Pressing Ctrl+C or waiting to get out of more

q is the clean way out; more otherwise waits for a key indefinitely.

q (or Q)
Expecting more in a script to pause for the user

When stdout isn't a terminal, more behaves like cat and doesn't page.

In scripts, write to a file or use read -p to pause explicitly

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Page through ~/data/orders.csv with more, find out which line you're on after two screens, then quit.

  2. 2

    Open ~/logs/app.log in more directly at the first line containing WARN.

  3. 3

    Dump ~/data/servers.txt and ~/data/notes.txt with file name banners into ~/both.txt using more.

Related commands

lessBrowse files and output: scroll, search, filter, followcatPrint and concatenate filesheadShow the first lines or bytes of a filetailShow the last lines of a file and follow it live
PrevioustailNextless
Linux / File Viewing & Editing / more

more

Page through text one screen at a time

Beginnerviewingpagerminimal systems

more shows a file or command output one screenful at a time and waits for a key. It's the original Unix pager: simpler than less, mostly forward-only, and it quits at the end of the file. You'll meet it on minimal systems, rescue shells and BusyBox containers where less isn't installed.

Syntaxmore [OPTION]... FILE... COMMAND | more

Watch it run

You need to read through a log that is longer than your screen on a box with only basic tools.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
more /var/log/app/app.log

One screenful, then the --More-- prompt with how far into the file you are (15%). more is waiting for a key.

Anatomy of a command

$
commandmore

The util-linux pager (BusyBox has its own smaller version).

How it works

more reads the terminal's size with the TIOCGWINSZ ioctl, prints one screen of lines, then puts the terminal into a raw-ish mode so it can read single key presses without Enter, and shows a --More-- prompt with a percentage (for files it knows the size of). Space shows the next screen, Enter the next line, / searches forward with a regular expression, and q quits. Moving backwards (b) only works for files, because a pipe can't be re-read; that limitation is the main reason less was written ('less is more'). When more reaches the end of the input it exits immediately and you're back at the prompt. If standard output is not a terminal (redirected or piped), more doesn't page at all: it behaves like cat, printing a :::::::::::::: header before each file when given several.

Options you'll actually use

Space / EnterNext screen / next line
bBack one screen (files only, not pipes)
/pattern, nSearch forward, repeat search
=Show the current line number
vOpen the file in an editor at the current line
qQuit
+N / +/PATTERNStart at line N / at the first match
-sSqueeze repeated blank lines

Common mistakes

Using more to read a big log you'll need to scroll back through

more only moves forward in pipes and exits at the end, so you can't go back up to an earlier line.

less file (back and forth, search both ways, follow mode)
Pressing Ctrl+C or waiting to get out of more

q is the clean way out; more otherwise waits for a key indefinitely.

q (or Q)
Expecting more in a script to pause for the user

When stdout isn't a terminal, more behaves like cat and doesn't page.

In scripts, write to a file or use read -p to pause explicitly

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Page through ~/data/orders.csv with more, find out which line you're on after two screens, then quit.

  2. 2

    Open ~/logs/app.log in more directly at the first line containing WARN.

  3. 3

    Dump ~/data/servers.txt and ~/data/notes.txt with file name banners into ~/both.txt using more.

Related commands

lessBrowse files and output: scroll, search, filter, followcatPrint and concatenate filesheadShow the first lines or bytes of a filetailShow the last lines of a file and follow it live
PrevioustailNextless