Command of the Day: more

May 9, 2007

“more” displays the named file(s) one screenful at a time. Simple enough and quite useful – but it’s got a few handy little features I was unaware of prior to getting to more in Linux in a Nutshell.

The straight-forward usage is something like:

$ more file.txt

The result of this will be the first screenful of file.txt with a prompt indicating what percentage of the file was being displayed.Up to today that was the extent of how I used more.

Usually when I’m using more I’m looking for something but I’m not necessarily sure what so grep isn’t what I want. But I’ve often got a pretty decent idea of what I want – perhaps a keyword.

more supports jumping right to the first instance of the pattern you care about. If more is already running you can enter:


And more will skip forward to the next instance of the pattern string. This can also be done upon invoking more using the command line syntax:

$ more +/pattern file.txt

If the pattern is found more will present the first match on the displayed screenful. If the pattern is not found more will indicate as much.

Now that you are at the first pattern match perhaps it was not the one you wanted. You can skip to the next match by hitting ‘n’ at the prompt. This is a great way to skip forward in the file quickly. If can skip more than one by typing a number before hitting ‘n’. For example at the more prompt if you type “12n” it will take you to the twelfth instance of the repeated pattern match.

Finally you can work with multiple files in more. The commands for moving between the files are “:n” to move the next file and “:p” to move to the previous. To help keep track of where you are you can use “:f” to display the file name and currently displayed line number.

There’s more going on than I previously realized.

I’m sorry. I couldn’t help it.

8 Responses to “Command of the Day: more”

  1. Eric Says:

    less is a more powerful command, as it lets you go up and down and all around through the file. It also employs a few vi commands (J is down, K is up, type /string and it will search for a string then after that a / will find the next one and a ? will find the previous one). Great little command to use🙂

  2. Onno Zweers Says:

    Hey! I didn’t know that:
    more +/pattern file.txt


  3. Icheb Says:


    You might want to check out the ‘less’ command, it does about the same thing as the ‘more’ command, however I personally find it to be more powerful, due to the fact you can also go back up again, which is something more doesn’t do.

    So far, I liked the articles!


  4. rubbsdecvik Says:

    less is more… I mean that less does many of the same things that more does, plus a little extra. You might want to take a look at it.


  5. GermanyZulu Says:

    Ditto, “less” lets you scroll *up* in files as well as down. It comes pre-installed in Ubuntu.

    It’s also what’s used when running the “man” command:

    less ~/.bashrc
    man bashrc

    Using “/” to search and all that works as well.

    Glad to see your finding exciting things in Linux: Welcome to the Future.


  6. MRibecky Says:

    Same here “less” lets you go backwards in the file, and search backwards(“?” in stead of “/”, and “N” in stead of “n”).
    Something that’s more important, in my opinion, about “more” and “less” is that it lets you read through the output of other commands. E.g. “cat long-file.txt | less”.

  7. Spook Says:

    Man, everyone else beat me to the “less is more” comment.

    Although, I hadn’t known that you could just specify the file in that manner – I always just did cat file | less.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: