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.