Which command do you use to read files on the terminal? isn’t cat command? “Yes,” I know cat is first preference to read file nothing is wrong to use cat command I use too.
But cat command has some limitations, What limitations? I’ll give you a scenario to understand more precisely. Have you ever tried to read the log from /var/log or any content that has many texts using a cat?
You have noticed it’s read a complete file, and this makes it quite challenging to find a specific line of text using the navigation button. And I’m tired of reading content using cat and finding an alternative way which is more convenient to use?
In this article, you will see how to read files using more commands with a few arguments or options with examples. Before heading, you should know what more command is?
What is more command?
A more command is used to print textfile content on a screen, and It simply displays the amount of text visible to your screen on one page at a time in your terminal.
Apart from this, more commands give you several options to navigate through the file, which make it much easier to read the content.
To read a file content, pass the following command:
$ more [FILE-NAME]
more command understands your affection for cat command, that’s a reason you have the choice to use cat and more command simultaneously using [|] pipe.
$ cat [FILE-NAME] | more
5 Funny Linux commands, Literally, we can do?
Finally, we reach a point from where we learn how to navigate throughout a file content. Usually, we use navigation keys to navigate, but this will not work at all.
To go down or forward in your open output, you can use multiple options Space bar or Enter key or d or Ctrl – D.
- Space bar or z: Jump to next page
- Enter key: Move down line by line
- d or Ctrl + D: Scroll down by default 11 number, default value change according to terminal size
- q or Q: To exit
To go up or back one page in your open output, you can use b or Ctrl – B.
Cautious:- Do not use Ctrl + D when connected to a remote system. It might end the current session.
This option will be a life savior when you know what you are looking for from a text file. It will save your time to scroll much.
To use this, you can use / and type the string or pattern you want to search.
I have STDOUT tar manual to a text file in the below image, and I need to find GNU using interactive options.
$ more text_dump
We have different approaches to perform the same task using +/ with more command. To explain you better check the below example
$ more +/pattern or string [FILE-NAME]
$ more +/"tar -A" text_dump
Output with Line Number
If you want to print out content that lies on number 50, that is also possible using +number or -number.
To print content store at line number 50, pass the below command:
$ more +50 text_dump.txt
$ cat --number text_dump | more +50
You should notice +number will print content starting from the beginning.
We have another option is -number which will display text content in reverse order, To do pass the below command:
$ more -50 text_dump.txt
$ cat --number text_dump | more -50
There is much to know about more commands. If you’re eager to know more, go to the Wikipedia page. In interactive mode, you can press ? or h for more options to learn.
We have noticed more command also has a limitation which can minimize using less command.
Make sure to read this:- Less Command in Linux with Examples
If you want to say Hi to me or want to suggest something feel free to contact me.
For short and simple pocket guide follow us on Instagram.
A man with a tech effusive who has explored some of the amazing technology stuff and is exploring more. While moving towards, I had a chance to work on Android development, Linux, AWS, and DevOps with several open-source tools.