2.3 Display contents of file |
2.3.1 Display contents of file (cat)
Next, let's check the contents of the file. It can be done by using the cat command.
We can check the contents of the file by command above.
Practice: cat command execution and line number display |
Let's check the file .bashrc in the home directory.
$ cat .bashrc ↵
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
:
: (Omitting)
$ cat -n .bashrc ↵
1 # .bashrc
2
3 # Source global definitions
4 if [ -f /etc/bashrc ]; then
:
: (Omitting)
|
The contents can be checked with cat command, and it was confirmed that line numbers can be attached
by using -n option.
2.3.2 Display with pager
When displaying the contents of the file using the cat command, the display will flow if there are many lines. Because the screen size that you use is under 25 lines in many cases, you can not check more lines that flowing.
Even if there are many lines, the function that controls the screen and stops the scroll in the middle is called paging, and the command that realizes that is called the pager.
There are two kinds of pagers, and it is more command and less command. The usages are the same, it
requires file name to be paged as an option.
more filename
less filename |
You can control the display by entering pager command. The commands in pager are as follows.
j
move below by one line
k
move above by one line
(space)
move below by one screen
b
move above by one screen
/word
Search the word. Jump to the next result by using n key
q
quit pager
|
Now you can check the long file contents as you like.
Practice: View file contents by using pager |
Let's check long file contents by pager command.
Please end it by q after trying various commands.
Please end it by q after trying various commands.
Don't you have any experiences that you can not use b-key in 'more' command? This comes
from 'more' command's origin.
The 'more' was born as pager for stopping scrolling. So it did not have any one-page-backfunction
which was assigned to b-key.
Since it was inconvenient, 'less' command was born. 'less' is the command which is
expanded from 'more' command, so to speak. For traditional Linux designs, 'more' is as it
was in the past. In recent Linux, the functions of the two may be same.
If 'more' command does not work, try 'less' command. In recent Linux, the 'less' command
is contained from the beginning.
|