Linux Commands – more
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed diff command in Linux which is used to compare the contents of files and directories.
https://cloudaffaire.com/linux-commands-diff/
In this blog post, we will discuss more command in Linux. more command is used as a filter for paging through text one screenful at a time. If you have a very long file that does not fit in the current screen, you can use more command to view the contents one screenful at a time. more command can work directly with a file or can be used with a pipe.
more command provides interactive mode like vi to interact with the file content. Below are different commands and their details that can be issued within more output in interactive mode.
command | details |
h or ? | Help; display a summary of these commands |
SPACE | Display next k lines of text. Defaults to current screen |
z | Display next k lines of text, defaults to current screen size |
RETURN | Display next k lines of text, defaults to 1 |
d or ^D | Scroll k lines, default is current scroll size, initially 11 |
q or Q | Exit more |
s | Skip forward k lines of text, defaults to 1 |
f | Skip forward k screenfuls of text, defaults to 1 |
b or ^B | Skip backwards k screenfuls of text, defaults to 1. Only works with file not pipe |
‘ | Go to the place where the last search started |
= | Display current line n |
/pattern | Search for kth occurrence of regular expression, defaults to 1 |
n | Search for kth occurrence of last regular expression defaults to 1 |
!command | Execute command in a subshell |
v | Start up an editor at current line |
^L | Redraw screen |
:n | Go to kth next file, defaults to 1 |
:p | Go to kth previous file, defaults to 1 |
:f | Display current file name and line number |
. | Repeat previous command |
** Some commands may be preceded by a decimal number, called k |
Linux Commands – more:
more command is used as a filter for paging through text one screenful at a time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
########################### ## Linux Commands | more ## ########################### ## Prerequisites: One Unix/Linux/POSIX-compliant operating system with bash shell ##----- ## more ##----- ## more [options] file... ## create a long file with 200 lines > myfile; i=1; while [ $i -le 200 ]; \ do echo "$i" >> myfile; ((i++)); done cat myfile ## displays the content of myfile at once more myfile ## displays one screenful at a time ## enter ==> scroll one line at a time ## space ==> scroll one screenful at a time ## q ==> exit ps -ax | more ## also works with pipe |
more command has an interactive mode like vi that enables you to interact with the output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
## command option in interactive mode more myfile ## display the output in interactive mode ## below is the list of commands supported ## in interactive mode, any other key results ## a bell sound ## h or ? ==> display help ## SPACE ==> scroll current screen size ## z arg ==> scroll current screen size (arg=new screen size). ## RETURN ==> scroll one line at a time ## d or ^D ==> scroll current scroll size ## q or Q ==> Exit more ## s ==> skip forward k lines of text, defaults to 1 ## f ==> skip forward k screenfuls of text, defaults to 1 ## b or ^B ==> skip backwards k screenfuls of text, defaults to 1. ## ' ==> go to the place where the last search started ## = ==> display current line n ## /pattern ==> search for kth occurrence of regular expression, defaults to 1 ## n ==> search for kth occurrence of last regular expression defaults to 1 ## !command ==> execute command in a subshell ## v ==> start up an editor at current line ## ^L ==> redraw screen ## :n ==> go to kth next file, defaults to 1 ## :p ==> go to kth previous file, defaults to 1 ## :f ==> display current file name and line number ## . ==> repeat previous command |
You can use more -<number> options to specify the of lines per screenful. The argument is a positive decimal integer.
1 2 3 4 5 6 |
## specify the no. of lines per screenful tput lines ## returns 46 in my terminal more myfile ## by default returns 46 lines (my terminal size) more -10 myfile ## returns 10 lines per screenful more -30 myfile ## can be any postive interger. |
You can use more +<number> to display file beginning from line number. The argument is a positive decimal integer.
1 2 3 4 |
## display file beginning from line number more +10 myfile ## output start from line number 10 more +30 myfile ## can be any postive integer |
You can use more +/<string> to display file beginning from search string match.
1 2 3 4 |
## display file beginning from search string match sed -i "100i hello" myfile ## inserts hello on line no. 100 of myfile more +/hello myfile ## display start form hello |
You can use more -s or –squeeze options to squeeze multiple blank lines into one.
1 2 3 4 5 6 7 8 9 10 11 |
## squeeze multiple blank lines into one. ## create a file with multiple empty lines > myfile; i=1; while [ $i -le 100 ]; \ do echo "$i" >> myfile; ((i++)); done echo -e "\n\n\n\n\n\n\n\n" >> myfile i=101; while [ $i -le 200 ]; \ do echo "$i" >> myfile; ((i++)); done more myfile ## displays multiple empty line between 100 and 101 more -s myfile ## squeeze multiple blank lines into one |
You can use more -l or –logical options to not pause after any line containing a ^L (form feed).
1 2 3 4 5 6 7 8 9 10 11 |
## not pause after any line containing a ^L (form feed) ## create a file with multiple form feed (^L) > myfile; i=1; while [ $i -le 100 ]; \ do echo "$i" >> myfile; ((i++)); done echo -e "\n\f\n\f\n\f\n\f\n" >> myfile i=101; while [ $i -le 200 ]; \ do echo "$i" >> myfile; ((i++)); done more myfile ## pause after any line containing a ^L (between 100 to 101) more -l myfile ## do not pause after any line containing a ^L |
In the interactive mode of more, if any illegal key is pressed, one bell alert is sounded. You can use more -d or –silent options to display help and suppress the bell sound when an illegal character is pressed.
1 2 3 4 5 6 7 |
## display help and prompt instead of a ringing bell more myfile ## by default more will sound the bell ## if any illegal key is press like k more -d myfile ## suppress the bell alert when illegal ## for example k is pressed |
more has different options to control the screen scroll. You can use more -f option to count logical rather than screen lines. You can use more -c option to not scroll, display text and clean line ends, and more -p option to not scroll, clean screen and display text.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
## control the screen scroll ## create a file with long lines > myfile; i=1; while [ $i -le 40 ]; \ do echo "$i" >> myfile; ((i++)); done ps -ax | sed 's/[^A-Za-z0-9]//g' | tr -d '[ \n]' >> myfile ps -ax | sed 's/[^A-Za-z0-9]//g' | tr -d '[ \n]' >> myfile echo -e "\n" >> myfile i=41; while [ $i -le 100 ]; \ do echo "$i" >> myfile; ((i++)); done ## hit space bar to display one screenful at a time and see the difference in behaviour more myfile ## normal output more -f myfile ## count logical rather than screen lines more -c myfile ## do not scroll, display text and clean line ends more -p myfile ## do not scroll, clean screen and display text |
Hope you have enjoyed this article. In the next blog post, we will discuss less command in Linux.