LearnLinux FoundationsReading Files

more

more - a hands-on Linux lab on a real virtual machine.

Page through a file too long to dump with more, the simple older pager: open it with more <file, move forward with Space, search forward with /word, and quit with q. Learn why its successor less gives you more.

You already know how to pour a whole file onto the screen and how to peek at just its top or bottom. Those work beautifully until a file is simply too long to take in one gulp. In intercept/logs there is a file called bulk.log. It is one single line ten thousand characters long. Dump it and it floods across your screen in an unreadable smear. The part you wanted has already scrolled off the top.

What you actually want is to read it the way you read a book: one page, stop, then the next page when you are ready. The tool that does that is more. It is a pager: instead of dumping the whole file at once, it shows you one screenful and waits for you to ask for the next.

The black boxes in this lesson are a practice terminal: a safe sandbox that only checks the one command each step teaches, so you cannot break anything. more is interactive, so the boxes here confirm the command that OPENS it; the keys you press once inside are taught as text. You drive the live pager for real on the machine at the end of the module.

You start more the same way you start any command that reads a file: the name, a space, then the path. Point it at the boot log messages.log in intercept/logs.

Before you run this, decide: will the log's lines print under your command like a normal dump, or will something take over the screen instead? Type this exact command and press Enter:

more ~/intercept/logs/messages.log

prompt: student@linuxcamp:~$ answer: more ~/intercept/logs/messages.log output: hint: Type more, a space, then the full path to the file: more ~/intercept/logs/messages.log

Nothing prints back here, and that is the honest picture: on the real machine more takes over the whole screen. It does not dump the file into your command history the way a plain dump would. It opens the file, parks you at the top, and holds there waiting for a keystroke. messages.log is only 8 lines, so its whole content fits on one screen and more shows it all at once. The interesting behavior starts when the file is taller than one screen, which is where the keys come in.

The instant a pager takes over your screen, the ordinary prompt is gone and your normal typing does nothing. Beginners meet more by accident, see a frozen-looking screen, and panic. Here is the escape, the single most important key in this whole lesson: press q, and more quits and drops you straight back to your prompt.

The q is short for quit. It works no matter where you are in the file, whether you have paged forward once or twenty times. If a screen ever fills up and stops responding to normal typing, that is almost always a pager waiting for you, and q is the way out.

Open the twelve-line report in more so there is a real file to practice quitting on. Before you run it, commit to your exit: which single key will you press to get your prompt back?

more ~/intercept/logs/report.txt

prompt: student@linuxcamp:~$ answer: more ~/intercept/logs/report.txt output: hint: Type more, a space, then the path to the report: more ~/intercept/logs/report.txt

Once report.txt is open in more on the real machine, a single press of q returns you to student@linuxcamp:~$. That is the whole safety net: any time a pager has your screen, q gives it back. Commit that one key to memory before you learn any other, because it is the one that gets you unstuck.

Quitting is the exit. Now the motion. Once you are inside more, two keys move you down through the file:

When more has more file below what is on screen, it shows a --More-- marker at the bottom to tell you there is more to come. When you reach the end of the file, more exits on its own and returns you to the prompt.

more moves in one direction: forward. Pressing Space walks you down the file page by page, and once you pass a line there is no built-in key in classic more to scroll back up to it. That one limitation is the reason a more capable pager exists, which you will meet at the end of this lesson.

Paging one screen at a time is fine for a short file, but on a long one you often want to jump straight to a word. Inside more you can. Press the / key, type a word, and press Enter, and more skips ahead to the next line that contains it.

Say you are paging through a log looking for the word error. Rather than press Space over and over, you type /error and Enter, and more jumps forward to the first line with error in it. After that first jump, pressing n (for next) moves to the following match, and the one after that, so you can hop from hit to hit.

Search in more only looks forward, from where you are now toward the end of the file. It does not search the part you have already paged past.

Open the report in more to have something to search. Before you run it, decide which word you would type after / to jump straight to the report's summary section:

more ~/intercept/logs/report.txt

prompt: student@linuxcamp:~$ answer: more ~/intercept/logs/report.txt output: hint: Same as before, open the report in more: more ~/intercept/logs/report.txt

With report.txt open, typing /SUMMARY and pressing Enter would jump more straight down to the line SECTION 2: SUMMARY, skipping the overview above it. Then n would look for the next SUMMARY further down. Forward search plus n turns a long file into something you navigate by keyword instead of by brute-force paging.

You have now met the whole of classic more: open a file, Space to page forward, / to search forward, q to quit. It is small and it is old, one of the oldest pagers on Unix, and its one real weakness is that it mostly only goes forward. Scroll past the line you wanted and you cannot easily scroll back to it.

That weakness is exactly why a successor was written, and it is called less. less does everything more does and then adds the missing half. It scrolls backward as freely as forward (the b key pages back up), it moves faster on huge files, and its search works in both directions. The name is a pun on an old saying, "less is more": the tool named less is the one that gives you *more*. less has its own lesson in this module. Here you only need the relationship: more is the simple original, and less is the fuller successor you reach for when you need to move around a file freely.

On many modern systems more has quietly grown a few of less's tricks, but you cannot count on that from machine to machine. Learn more for the guaranteed basics (Space, /, q) and reach for less whenever you need to scroll back up.

Scaffolding off. No command is shown this time. You have every piece you need.

Back at the start you met bulk.log in intercept/logs, the one file too long to dump: a single line of ten thousand characters. That is the perfect job for a pager. Open bulk.log in more so you could page through it one screen at a time. Recall the shape from the earlier steps: the command name, a space, then the path.

prompt: student@linuxcamp:~$ answer: more ~/intercept/logs/bulk.log output: hint: It is the same open-in-more shape you used on messages.log and report.txt, pointed at bulk.log: more ~/intercept/logs/bulk.log

That opens the ten-thousand-character log in the pager instead of blasting it across your screen. From inside more you would press Space to walk forward through it and q to quit when you are done. You recalled the whole invocation from memory, which is exactly the move the real machine will ask of you.

One more, still from memory. The boot log messages.log lives in the same intercept/logs folder. Open it in the pager too.

prompt: student@linuxcamp:~$ answer: more ~/intercept/logs/messages.log output: hint: Same shape, different file: more ~/intercept/logs/messages.log

Two challenges, two clean recalls. The shape never changes: more, a space, the path. On the real machine this one shows all 8 lines at once, since the whole file fits on a single screen, and a press of q hands the prompt back.

You earned this cheat sheet. The first row is the command you typed; the rest are the keys you press once you are inside more:

The one idea to carry away: more shows a long file one screen at a time so it never floods you. Space to go forward, / to search forward, and q when you are done. When you need to scroll back up or move around freely, that is less, the fuller successor covered in its own lesson.

If a command ever fills your screen and stops responding to normal typing, you are probably stuck in a pager like more or less. Do not close the terminal. Press q to quit the pager and get your prompt back.

The practice terminal has shown you how to open more and taught you the keys that drive it: Space to page forward, / to search, and q to quit. The Reading Files module ends with one real Linux machine, and that is where you page through a file for real.

In the reading-files capstone mission, a Linux VM boots just for you on a live copy of the same intercept folder. That includes the ten-thousand-character bulk.log. There you open it in more and actually press the keys: Space to move down a screen, / to jump to a word, q to get out. One difference from here: the lab shows no commands. You read the objective, recall the tool, and type it yourself. That recall is what makes it stick.

Finish the other Reading Files lessons, on less and the rest of the reading kit, then go page the intercept for real.

Practice more in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.