Looking at a Linux file with the more command
A common way to use the Linux more command is to display the contents of a text file. Where you might normally "cat out" the contents of a text file with the cat command, like this:
cat /etc/passwd
a problem with this approach is that when the file is long, all the output scrolls off the top of your screen. The Linux more command solves this problem by letting you scroll the output one screenful of data at a time. For this use, just use the more command instead of the cat command, like this:
more /etc/passwd
Now you can see the file contents on screen, and you can also scroll through the file output. On modern Linux systems you can use the [UpArrow] and [DownArrow] keys to scroll through the display. You can also use these keys to move through the output:
◉ [Space] - scrolls the display, one screenful of data at a time
◉ [Enter] - scrolls the display one line
◉ [b] - scrolls the display backwards one screenful of data
◉ [/] - lets you search the text, just like you would in the vi/vim editor
Use the Linux more command in a pipeline
It's also very common to use the Linux more command in a command pipeline. For instance, let's say you want to look at a list of system processes, but don't want them to all scroll off the top of your screen. In this case you use the more command with the ps command, like this:
ps auxwww | more
You can use the more command at the end of any Linux command pipeline, for example, something like this:
grep 'foo' myfile.txt | grep bar | more
The 'less' command
Most Unix and Linux systems also now include a less command. It works similarly to the more command, but has a few improved options. Check it out, or read the man (manual) pages for both commands to find out which one you prefer.
0 comments:
Post a Comment