Linux OS (iii) more, less, head, tail

more command

more命令会一页一页的显示
命令格式: more [选项] 文件

Common parameters

parameter description
+n From the start page n display
-n Screen size is defined as the n-th row
+/pattern The search string (pattern) before each file is displayed, and then began to show before and after the string after two lines
-c From the top of the screen is cleared, and then display

Common Operations

symbol description
= Output line number of the current row
q Quit more
space bar Scroll down a screen
b Return to the previous screen

Example of the

Start from the fifth row displays the contents of the file test.log
more +5 test.log

Example two

Find the first file test.log 'g' string line appears
more + / g test.log

Example Three

Set the number of lines per screen is 5
More -5 test.log

Example Four

Use || and more command displays the / etc directory information
|| / etc | more -10

less command

less命令也是对文件或其他输出进行分用显示的工具
命令格式:less 【选项】 文件

Common parameters

parameter description
-e After the end of the file is displayed automatically leave
-f Forced to open a special file, such as a peripheral device number, directory and binary files
-i Ignore case when searching
-m Shows the percentage is similar to the more command
-N Display line numbers for each line
-s Empty display continuous line of conduct

Common Operations

symbol description
/ String Down search 'string' function
? String Search up "string" feature
n Repeat the search
N Front inverted repeat a search
b Turn one page forward
d Backward half page
q Exit the less command
space bar Back down one page
UP ARROW Flip up one line

Common examples
Example a: test.log realizing content file and line number
less -N test.log
Example Two: test.log display content file, the search string "AC"
less test.log
/ AC
Example Three: ps to view and process information displayed by the less pager
ps -f | less

head command

head主要是用来显示档案的开头至标准中输出,默认行为10行
命令格式
head [选项]  [文件]

Common parameters

parameter description
-q Hide file name
-v Displays the file name
-c <byte> The number of bytes the display
-n <line number> 显示行数

常用范例
例一:试试test.log文件中前5行的内容
head -n 5 test.log
例二:显示test.log和data.log文件中的前5行内容
head -n 5 test.log data.log

tail命令

tail命令主要用于显示指定文件末尾。常用来查看日志文件 命令格式:tail 【选项】 【文件】

常用参数

参数 描述
-f 循环读取
-q 不显示处理信息
-v 显示详细的处理信息
-c<字节> 显示的字节数
-n 显示行数

常用范例
例一:显示test.log文件中的最后5行内容
tail -n 5 test.log
例二:打印某日志test.log文件中的最后5行内容,不断的将新写入的日志显示出来
tail -n 5 -f test.log

发布了17 篇原创文章 · 获赞 0 · 访问量 499

Guess you like

Origin blog.csdn.net/HexString/article/details/104747633