Linux more command in one line

Linux more command

On Unix-like operating systems, the more command displays text, one screen at a time.

This page covers the GNU/Linux version of more.

Description

more is a filter for paging through text one screen at a time. It does not provide as many options or enhancements as less, but is nevertheless quite useful and simple to use.

Syntax

Options

-num lines Sets the number of lines that makes up a screenful. The lines must be an integer.
-d With this option, more prompts the user with the message «[Press space to continue, ‘q’ to quit.]» and display «[Press ‘h’ for instructions.]» when an illegal key is pressed, instead of ringing a bell.
-l more usually treats ^L (CONTROL-L, the form feed) as a special character, and pauses after any line containing it. The -l option prevents this behavior.
-f Causes more to count logical, rather than screen lines (i.e., long lines are not wrapped).
-p Do not scroll. Instead, clear the whole screen and then display the text. This option is switched on automatically if the more executable is named page.
-c Do not scroll. Instead, paint each screen from the top, clearing the remainder of each line as it is displayed.
-s Squeeze multiple blank lines into one blank line.
-u Do not display underlines.
+/string Search for the string string, and advance to the first line containing string when the file is displayed.
+num Start displaying text at line number num.

Commands

When displaying a file, more can be controlled with a set of commands loosely based on the text editor vi. Some commands can be preceded by a decimal number referred to as k in the following descriptions.

h, ? Show help (display a brief command summary). If you forget all the other commands, remember this one!
[k]SPACE Pressing the spacebar displays the next k lines of text. If k is not specified, more displays a full screen of new text.
[k]z Like pressing SPACE, but k becomes the new default number of lines to display.
[k]RETURN Pressing the Enter or Return key displays next k lines of text. The default is 1 line. If specified, k becomes the new default.
[k]d, [k]^D Pressing d or CONTROL-D scrolls k lines. The default is the current scroll size, which is initially 11 lines. If specified, k becomes the new default.
q, Q, ^C Pressing q, Q, or CONTROL-C (the interrupt key) exits the program.
[k]s Skip forward k lines of text. Defaults to 1.
[k]f Skip forward k screenfuls of text. Defaults to 1.
b, ^B Pressing b or CONTROL-B skips backward k lines of text. Defaults to 1. (This only works when viewing files, not piped input).
Go to the place where the previous search started.
= Display the current line number.
[k]/pattern Search for the kth occurrence of the regular expression pattern. Defaults to 1.
[k]n Search for the kth occurrence of the last regular expression searched for, which defaults to 1.
!command, :!command Execute command in a subshell.
v Start up an editor at current line. The editor is taken from the environment variable VISUAL if it’s defined, or EDITOR if VISUAL is undefined; if neither is defined, defaults to «vi».
^L Pressing CONTROL-L redraws the screen.
[k]:n Go to the kth next file. Defaults to 1.
[k]:p Go to the kth previous file. Defaults to 1.
:f Display the current file name and line number.
. Repeat previous command.
Читайте также:  Ol 2834 драйвер windows 10

Environment

more uses the values of the following environment variables, if they are defined:

MORE Default more options. If this variable is set, more reads as the default set of options to use. Any options specified on the command line override the options specified in $MORE.
SHELL The current shell in use (this variable is normally set by the shell itself at login time).
TERM The current terminal type. This value is used by more to determine the proper way to manipulate the screen.

Examples

Display the contents of file myfile.txt, beginning at line 3.

Display the contents of file myfile.txt, beginning at the first line containing the string «hope».

List the contents of the current directory with ls, using more to display the list one screen at a time.

cat — Output the contents of a file.
csh — The C shell command interpreter.
ctags — Create tag files for source code.
less — Scrolling text viewer.
man — Display the manual page of a given command.
nroff — Format documents for terminal display or line-printer.
script — Record everything printed on your screen.
sh — The Bourne shell command interpreter.
ul — Translate underscores to underlining.

Источник

more command in Linux with Examples

more command is used to view the text files in the command prompt, displaying one screen at a time in case the file is large (For example log files). The more command also allows the user do scroll up and down through the page. The syntax along with options and command is as follows. Another application of more is to use it with some other command after a pipe. When the output is large, we can use more command to see output one by one.

Syntax:

more [-options] [-num] [+/pattern] [+linenum] [file_name]

  • [-options]: any option that you want to use in order to change the way the file is displayed. Choose any one from the followings: (-d, -l, -f, -p, -c, -s, -u)
  • [-num]: type the number of lines that you want to display per screen.
  • [+/pattern]: replace the pattern with any string that you want to find in the text file.
  • [+linenum]: use the line number from where you want to start displaying the text content.
  • [file_name]: name of the file containing the text that you want to display on the screen.

While viewing the text file use these controls:

Enter key: to scroll down line by line.
Space bar: To go to the next page.
b key: To go to back one page.

Options:

    -d : Use this command in order to help the user to navigate. It displays “[Press space to continue, ‘q’ to quit.]” and displays “[Press ‘h’ for instructions.]” when wrong key is pressed.

Example:


-f : This option does not wrap the long lines and displays them as such.

Example:


-p : This option clears the screen and then displays the text.

Example:


-c : This command is used to display the pages on the same area by overlapping the previously displayed text.

Example:


-s : This option squeezes multiple blank lines into one single blank line.

Example:


-u : This option omits the underlines.

Example:
+/pattern : This option is used to search the string inside your text document. You can view all the instances by navigating through the result.

Читайте также:  Windows 10 файл подкачки 8gb

Example:


+num : This option displays the text after the specified number of lines of the document.

Example:

Using more to Read Long Outputs: We use more command after a pipe to see long outputs. For example, seeing log files, etc.

Источник

How to Use More Command in Linux to Read Large Text Files

When you are new to Linux, you try to use the cat command all the time to read the content of a file. This works great for files with only a few lines out of output, but larger files quickly scroll content past the user making it difficult, or even impossible for you to find what you need.

Cat Command Problem

The cat command is certainly not very practical for viewing large files. You don’t want your entire screen to be filled with the file content.

What you can do here is to use either ‘less command’ or ‘more command’. We’ve already covered the less command on Linux Handbook so I am going to show you how to use more command in this tutorial.

Using more command to read text files in Linux terminal

The more command opens a text file in page views. You can read page by page and when you quit more, there will be no output visible on the screen. Your terminal will be clean and pristine.

More More View

With more you are able to easily scroll through data one page at a time. You can use the following methods for navigation.

Input Action
Down Arrow / Space Bar Scroll Down (One Page)
Up Arrow / B Scroll Up (One Page)
Enter Scroll One Line at a Time
– number The Number of Lines per Screenful
+ number Display File Beginning from Line Number
+/ string Display File Beginning from Search String Match
q Quit viewing the text file and return to screen

While using more, you can enter q to quit at anytime or h to display the built-in help.

Display n number of lines per screen

Typing an -n (where n is an integer) after the command will display only n number of lines as a page.

Move 2 lines at a time

Skip the first n number of lines

Typing +n (where n is an integer) after the command will skip to that line number before displaying your content.

Search for a string using more command

You can skip to the first instance of a specified string using +/string after our command.

To find the next instance, you can type /string inside the more view to search.

Skip multiple blank lines with -s option of more command

If you have multiple blank lines together, you can trim them into a single blank line with option -s.

Run more command with help options displayed

If you are new to more, you can run it with option -d. This way, it keeps on showing help for navigating.

In addition to that, if you used any illegal character or command in more view, it suggests using help methods using h which displays detailed instructions for navigation or exit.

Conclusion

There are also a few more tricks and tips included that you can look at. Of course, you can always look at man page of more command for details.

Personally, I prefer using less command over more command.

I hope this tutorial gave you enough to survive the more command. I welcome your questions and suggestions.

Источник

Linux more Command Explained with Examples

If you are used to working with Linux, you will find a lot of file text in Linux world. Configuration files and log files are usually kept in text format. But those files usually has long content.

You can not view them all in one page. So we need pagination to those files. And to do that, we can use Linux more command.

More command is a command for displaying a long text file per page at a time. More command is a built-in command in Linux.

How to use linux more command

To use more command, we just need to type :

For example, we want to see the content of syslog file located in /var/log directory. We can type :

We see that an indicator on the bottom left. It shows us number 0%. It means that the file is long enough, so the first page is 0% of the total page. To scroll down, use space button. Then we see that the indicator number is increased.

1) Limit lines per page

When you run more command, it will fill your screen with the content of the file you are seeing using more. You can limit it into some lines for each page. To do this you can use -num option.

For example, you want to limit the lines only 12 lines for each page. Then you can type :

Now it will limit 12 lines per page. When you press spacebar to scroll down, it will show you more 12 lines.

2) Display user message

As we knew, more will display an indicator at the bottom left to show our position in percentage. For those who run more at the first time, he/she may guess how to scroll the page down. To avoid this, we can use -d option that will make more command display a user message like this “[Press space to continue, ‘q’ to quit.]” .

If user press a button other than button ‘space’ and ‘q’ , then more will display a warning message “[Press ‘h’ for instructions.]” .

If you press h button, it will display a help message :

One of the interesting command is the b button. b button allow you to go back to previous page. In other word, b button allow you to scroll up.

You can know that you are in the previous page from the line . backup 1 page at the top left area.

3) Suppress scroll

With -c option, more will not scroll the page. It will clear the previous page and put the next page or lines there.

If you press space button, the next page or lines is still at the same size.

4) Squeeze multiple blank lines

To squeeze it, we can use -s option. Here’s a sample :

When we add -s option :

5) Search string

If your log file is long enough, it’s not easy to find a string that you want. The search string can help you. Using +/string can search a string for you and put the keyword on the beginning of the line. Let say we want to search “dhclient” in /var/logs/syslog file. Then the syntax is :

Then to continue the search on the next line, you can press / button following by dhclient word.

6) Display content start with specific line

You can also display a content of file start with specific line using +num option. For example, we have a file with 15 lines inside it.

Then we want to display a file named doc_30.txt starting from the line number 5. The command will be like this :

Can we use it to display binary file?

The answer is No. More will give you a message about this. Here’s a sample.

Conclusion

More is one of the basic tool to display a content of text file. More cannot be used to display binary file. As usual, we can always type man more or more —help to explore more detail about the usage of more command.

Источник

Читайте также:  Как управлять windows через android
Оцените статью