当前位置:   article > 正文

Linux Centos 7查看文件内容_centos7查看文件内容

centos7查看文件内容

目录

 

一、linux CentOS7常用查看文件内容的指令

1.1、概述

1.2、查看指令文档

1.3、cat指令

1.3.1、语法

1.3.2、cat指令文档

1.3.2、cat -A

1.3.3、cat -b

1.3.4、cat -E

1.3.5、cat -n

1.3.6、cat -e

1.3.7、cat  -s

1.3.8、cat  -t  

1.3.9、cat -T

1.3.10、cat -u (ignored)

1.3.11、cat -v

二、tac  文件内容从最后一行开始显示

三、nl  显示行号

3.1、nl --help

3.2、应用

四、more   一页一页的翻动

4.1、more --help

4.2、应用

五、less  一页一页翻滚

5.1、less --help

5.2、应用

六、head 取出文件前面几行

6.1、head --help

6.2、应用

七、tail 取出文件后面几行

7.1、tail --help

7.2、应用


一、linux CentOS7常用查看文件内容的指令

1.1、概述

  • cat  由第一行开始显示文件内容
  • tac  从最后一行开始显示,可以看出 tac 是 cat 的倒着写!
  • nl   显示的时候,顺道输出行号!
  • more 一页一页的显示文件内容
  • less 与 more 类似,但是比 more 更好的是,他可以往前翻页!
  • head 只看头几行
  • tail 只看尾巴几行

1.2、查看指令文档

man cat

1.3、cat指令

  1. [user@localhost ~]$ cat -E --help
  2. 用法:cat [选项]... [文件]...
  3. 将[文件]或标准输入组合输出到标准输出。
  4. -A, --show-all 等于-vET
  5. -b, --number-nonblank 对非空输出行编号
  6. -e 等于-vE
  7. -E, --show-ends 在每行结束处显示"$"
  8. -n, --number 对输出的所有行编号
  9. -s, --squeeze-blank 不输出多行空行
  10. -t 与-vT 等价
  11. -T, --show-tabs 将跳格字符显示为^I
  12. -u (被忽略)
  13. -v, --show-nonprinting 使用^ 和M- 引用,除了LFD和 TAB 之外
  14. --help 显示此帮助信息并退出
  15. --version 显示版本信息并退出
  16. 如果没有指定文件,或者文件为"-",则从标准输入读取。
  17. 示例:
  18. cat f - g 先输出f 的内容,然后输出标准输入的内容,最后输出g 的内容。
  19. cat 将标准输入的内容复制到标准输出。
  20. GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
  21. 请向<http://translationproject.org/team/zh_CN.html> 报告cat 的翻译错误
  22. 要获取完整文档,请运行:info coreutils 'cat invocation'
  23. [user@localhost ~]$

1.3.1、语法

cat [OPTION]... [FILE]...

查看issue文件内容

  1. [root@localhost user]# cat /etc/issue
  2. \S
  3. Kernel \r on an \m


 

  • -A, --show-all                  显示所有,可列出一些特殊字符而不是空白而已
  • -b, --number-nonblank   列出行号,仅针对非空白行做行号显示,空白行不标行号
  • -e     equivalent to -vE   
  • -E, --show-ends            将结尾的断行字节 $ 显示出来
  • -n, --number                 列印出行号,连同空白行也会有行号,与 -b 的选项不同
  • -s, --squeeze-blank
  • -t     equivalent to -vT
  • -T, --show-tabs              将 [tab] 按键以 ^I 显示出来;
  • -u (ignored)
  • -v, --show-nonprinting     列出一些看不出来的特殊字

1.3.2、cat指令文档

  1. CAT(1) User Commands CAT(1)
  2. NAME
  3. cat - concatenate files and print on the standard output
  4. SYNOPSIS
  5. cat [OPTION]... [FILE]...
  6. DESCRIPTION
  7. Concatenate FILE(s), or standard input, to standard output.
  8. -A, --show-all
  9. equivalent to -vET
  10. -b, --number-nonblank
  11. number nonempty output lines, overrides -n
  12. -e equivalent to -vE
  13. -E, --show-ends
  14. display $ at end of each line
  15. -n, --number
  16. number all output lines
  17. -s, --squeeze-blank
  18. suppress repeated empty output lines
  19. -t equivalent to -vT
  20. -T, --show-tabs
  21. display TAB characters as ^I
  22. -u (ignored)
  23. -v, --show-nonprinting
  24. use ^ and M- notation, except for LFD and TAB
  25. --help display this help and exit
  26. --version
  27. output version information and exit
  28. With no FILE, or when FILE is -, read standard input.
  29. EXAMPLES
  30. cat f - g
  31. Output f's contents, then standard input, then g's contents.
  32. cat Copy standard input to standard output.
  33. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report cat translation bugs to <http://transla‐
  34. tionproject.org/team/>
  35. AUTHOR
  36. Written by Torbjorn Granlund and Richard M. Stallman.
  37. COPYRIGHT
  38. Copyright © 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later
  39. <http://gnu.org/licenses/gpl.html>.
  40. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by
  41. law.
  42. SEE ALSO
  43. tac(1)
  44. The full documentation for cat is maintained as a Texinfo manual. If the info and cat programs are properly
  45. installed at your site, the command
  46. info coreutils 'cat invocation'
  47. should give you access to the complete manual.
  48. GNU coreutils 8.22 November 2020 CAT(1)

1.3.2、cat -A

由第一行开始显示文件内容

1.3.3、cat -b

列出行号,仅针对非空白行做行号显示,空白行不标行号

  1. [user@localhost ~]$ cat -b tr
  2. 1 enfdieogjidjfdgj
  3. 2 dffd12487594
  4. 3 iehgjh5934785
  5. 4 f84thifkjgh8934th+i49/GU84HG
  6. 5 (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  7. 6 HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  8. 7 IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  9. 8 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2] Q
  10. 9 As M=-PKGMV TUHG9U=] [FL';V,C U43JGBN GJNFSKDL,1 20 R =ITUT950JGT
  11. 10 R
  12. 11 Q03-TJU5INOUHW034H

1.3.4、cat -E

-E, --show-ends            将结尾的断行字节 $ 显示出来

1.3.5、cat -n

-n, --number                 列印出行号,连同空白行也会有行号,与 -b 的选项不同

1.3.6、cat -e

1.3.7、cat  -s

  1. enfdieogjidjfdgj
  2. dffd12487594
  3. iehgjh5934785
  4. f84thifkjgh8934th+i49/GU84HG
  5. (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  6. HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  7. IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  8. 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2] Q
  9. As M=-PKGMV TUHG9U=] [FL';V,C U43JGBN GJNFSKDL,1 20 R =ITUT950JGT
  10. R
  11. Q03-TJU5INOUHW034H

1.3.8、cat  -t  

  1. [user@localhost ~]$ cat -t tr
  2. enfdieogjidjfdgj
  3. dffd12487594
  4. iehgjh5934785
  5. f84thifkjgh8934th+i49/GU84HG
  6. (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  7. HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  8. IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  9. 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2]^IQ
  10. As M=-PKGMV TUHG9U=]^I[FL';V,C U43JGBN GJNFSKDL,1 20 R^I=ITUT950JGT
  11. R
  12. Q03-TJU5INOUHW034H^I

1.3.9、cat -T

  将 [tab] 按键以 ^I 显示出来;

  1. [user@localhost ~]$ cat -T tr
  2. enfdieogjidjfdgj
  3. dffd12487594
  4. iehgjh5934785
  5. f84thifkjgh8934th+i49/GU84HG
  6. (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  7. HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  8. IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  9. 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2]^IQ
  10. As M=-PKGMV TUHG9U=]^I[FL';V,C U43JGBN GJNFSKDL,1 20 R^I=ITUT950JGT
  11. R
  12. Q03-TJU5INOUHW034H^I
  13. [user@localhost ~]$

1.3.10、cat -u (ignored)

  1. user@localhost ~]$ cat -u tr
  2. enfdieogjidjfdgj
  3. dffd12487594
  4. iehgjh5934785
  5. f84thifkjgh8934th+i49/GU84HG
  6. (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  7. HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  8. IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  9. 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2] Q
  10. As M=-PKGMV TUHG9U=] [FL';V,C U43JGBN GJNFSKDL,1 20 R =ITUT950JGT
  11. R
  12. Q03-TJU5INOUHW034H

1.3.11、cat -v

列出一些看不出来的特殊字

  1. [user@localhost ~]$ cat -v tr
  2. enfdieogjidjfdgj
  3. dffd12487594
  4. iehgjh5934785
  5. f84thifkjgh8934th+i49/GU84HG
  6. (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  7. HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  8. IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  9. 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2] Q
  10. As M=-PKGMV TUHG9U=] [FL';V,C U43JGBN GJNFSKDL,1 20 R =ITUT950JGT
  11. R

二、tac  文件内容从最后一行开始显示

tac与cat命令刚好相反,文件内容从最后一行开始显示,可以看出 tac 是 cat 的倒着写

  1. [user@localhost ~]$ tac tr
  2. Q03-TJU5INOUHW034H
  3. R
  4. As M=-PKGMV TUHG9U=] [FL';V,C U43JGBN GJNFSKDL,1 20 R =ITUT950JGT
  5. 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2] Q
  6. IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  7. HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  8. (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  9. f84thifkjgh8934th+i49/GU84HG
  10. iehgjh5934785
  11. dffd12487594
  12. enfdieogjidjfdgj
  13. [user@localhost ~]$

三、nl  显示行号

nl [-bnw] 文件

选项与参数:

  • -b :指定行号指定的方式,主要有两种:
    -b a :表示不论是否为空行,也同样列出行号(类似 cat -n);
    -b t :如果有空行,空的那一行不要列出行号(默认值);
  • -n :列出行号表示的方法,主要有三种:
    -n ln :行号在荧幕的最左方显示;
    -n rn :行号在自己栏位的最右方显示,且不加 0 ;
    -n rz :行号在自己栏位的最右方显示,且加 0 ;
  • -w :行号栏位的占用的位数。

3.1、nl --help

  1. [user@localhost ~]$ nl --help
  2. 用法:nl [选项]... [文件]...
  3. Write each FILE to standard output, with line numbers added.
  4. With no FILE, or when FILE is -, read standard input.
  5. Mandatory arguments to long options are mandatory for short options too.
  6. -b, --body-numbering=样式 使用指定样式编号文件的正文行目
  7. -d, --section-delimiter=CC 使用指定的CC 分割逻辑页数
  8. -f, --footer-numbering=样式 使用指定样式编号文件的页脚行目
  9. -h, --header-numbering=样式 使用指定样式编号文件的页眉行目
  10. -i, --page-increment=数值 设置每一行遍历后的自动递增值
  11. -l, --join-blank-lines=数值 设置数值为多少的若干空行被视作一行
  12. -n, --number-format=格式 根据指定格式插入行号
  13. -p, --no-renumber 在逻辑页数切换时不将行号值复位
  14. -s, --number-separator=字符串 可能的话在行号后添加字符串
  15. -v, --starting-line-number=数字 每个逻辑页上的第一行的行号
  16. -w, --number-width=数字 为行号使用指定的栏数
  17. --help 显示此帮助信息并退出
  18. --version 显示版本信息并退出
  19. 默认的选项设置是-v1 -i1 -l1 -sTAB -w6 -nrn -hn -bt -fn。CC 是用于分隔
  20. 逻辑页数的两个分界符,其中缺失的第二个字符暗含了":",如果您要指定"\",
  21. 请输入"\\"。可用的样式如下:
  22. a 对所有行编号
  23. t 对非空行编号
  24. n 不编行号
  25. pBRE 只对符合正则表达式BRE 的行编号
  26. FORMAT 是下列之一:
  27. ln 左对齐,空格不用0 填充
  28. rn 右对齐,空格不用0 填充
  29. rz 右对齐,空格用0 填充
  30. GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
  31. 请向<http://translationproject.org/team/zh_CN.html> 报告nl 的翻译错误
  32. 要获取完整文档,请运行:info coreutils 'nl invocation'
  33. [user@localhost ~]$

3.2、应用

  1. [user@localhost ~]$ nl tr
  2. 1 enfdieogjidjfdgj
  3. 2 dffd12487594
  4. 3 iehgjh5934785
  5. 4 f84thifkjgh8934th+i49/GU84HG
  6. 5 (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  7. 6 HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  8. 7 IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  9. 8 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2] Q
  10. 9 As M=-PKGMV TUHG9U=] [FL';V,C U43JGBN GJNFSKDL,1 20 R =ITUT950JGT
  11. 10 R
  12. 11 Q03-TJU5INOUHW034H
  13. [user@localhost ~]$

四、more   一页一页的翻动

 more 这个程序的运行过程中,你有几个按键可以按的:

  • 空白键 (space):代表向下翻一页;
  • Enter         :代表向下翻『一行』;
  • /字串         :代表在这个显示的内容当中,向下搜寻『字串』这个关键字;
  • :f            :立刻显示出档名以及目前显示的行数;
  • q             :代表立刻离开 more ,不再显示该文件内容。
  • b 或 [ctrl]-b :代表往回翻页,不过这动作只对文件有用,对管线无用。

4.1、more --help

  1. more: 未知选项 -help
  2. 用法:more [选项] 文件...
  3. 选项:
  4. -d 显示帮助,而不是响铃
  5. -f 统计逻辑行数而不是屏幕行数
  6. -l 抑制换页(form feed)后的暂停
  7. -p 不滚屏,清屏并显示文本
  8. -c 不滚屏,显示文本并清理行尾
  9. -u 抑制下划线
  10. -s 将多个空行压缩为一行
  11. -NUM 指定每屏显示的行数为 NUM
  12. +NUM 从文件第 NUM 行开始显示
  13. +/STRING 从匹配搜索字符串 STRING 的文件位置开始显示
  14. -V 输出版本信息并退出
  15. [user@localhost ~]$

4.2、应用

  1. [user@localhost ~]$ more tr
  2. enfdieogjidjfdgj
  3. dffd12487594
  4. iehgjh5934785
  5. f84thifkjgh8934th+i49/GU84HG
  6. (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  7. HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  8. IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  9. 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2] Q
  10. As M=-PKGMV TUHG9U=] [FL';V,C U43JGBN GJNFSKDL,1 20 R =ITUT950JGT
  11. R
  12. Q03-TJU5INOUHW034H

五、less  一页一页翻滚

5.1、less --help

  1. SUMMARY OF LESS COMMANDS
  2. Commands marked with * may be preceded by a number, N.
  3. Notes in parentheses indicate the behavior if N is given.
  4. A key preceded by a caret indicates the Ctrl key; thus ^K is ctrl-K.
  5. h H Display this help.
  6. q :q Q :Q ZZ Exit.
  7. ---------------------------------------------------------------------------
  8. MOVING
  9. e ^E j ^N CR * Forward one line (or N lines).
  10. y ^Y k ^K ^P * Backward one line (or N lines).
  11. f ^F ^V SPACE * Forward one window (or N lines).
  12. b ^B ESC-v * Backward one window (or N lines).
  13. z * Forward one window (and set window to N).
  14. w * Backward one window (and set window to N).
  15. ESC-SPACE * Forward one window, but don't stop at end-of-file.
  16. d ^D * Forward one half-window (and set half-window to N).
  17. u ^U * Backward one half-window (and set half-window to N).
  18. ESC-) RightArrow * Left one half screen width (or N positions).
  19. ESC-( LeftArrow * Right one half screen width (or N positions).
  20. F Forward forever; like "tail -f".
  21. r ^R ^L Repaint screen.
  22. R Repaint screen, discarding buffered input.
  23. ---------------------------------------------------
  24. Default "window" is the screen height.
  25. Default "half-window" is half of the screen height.
  26. ---------------------------------------------------------------------------
  27. SEARCHING
  28. /pattern * Search forward for (N-th) matching line.
  29. ?pattern * Search backward for (N-th) matching line.
  30. n * Repeat previous search (for N-th occurrence).
  31. N * Repeat previous search in reverse direction.
  32. ESC-n * Repeat previous search, spanning files.
  33. ESC-N * Repeat previous search, reverse dir. & spanning files.
  34. ESC-u Undo (toggle) search highlighting.
  35. &pattern * Display only matching lines
  36. ---------------------------------------------------
  37. A search pattern may be preceded by one or more of:
  38. ^N or ! Search for NON-matching lines.
  39. ^E or * Search multiple files (pass thru END OF FILE).
  40. ^F or @ Start search at FIRST file (for /) or last file (for ?).
  41. ^K Highlight matches, but don't move (KEEP position).
  42. ^R Don't use REGULAR EXPRESSIONS.
  43. ---------------------------------------------------------------------------
  44. JUMPING
  45. g < ESC-< * Go to first line in file (or line N).
  46. G > ESC-> * Go to last line in file (or line N).
  47. p % * Go to beginning of file (or N percent into file).
  48. t * Go to the (N-th) next tag.
  49. T * Go to the (N-th) previous tag.
  50. { ( [ * Find close bracket } ) ].
  51. } ) ] * Find open bracket { ( [.
  52. ESC-^F <c1> <c2> * Find close bracket <c2>.
  53. ESC-^B <c1> <c2> * Find open bracket <c1>
  54. ---------------------------------------------------
  55. Each "find close bracket" command goes forward to the close bracket
  56. matching m<letter> Mark the current position with <letter>.
  57. '<letter> Go to a previously marked position.
  58. '' Go to the previous position.
  59. ^X^X Same as '.
  60. ---------------------------------------------------
  61. A mark is any upper-case or lower-case letter.
  62. Certain marks are predefined:
  63. ^ means beginning of the file
  64. $ means end of the file
  65. ---------------------------------------------------------------------------
  66. CHANGING FILES
  67. :e [file] Examine a new file.
  68. ^X^V Same as :e.
  69. :n * Examine the (N-th) next file from the command line.
  70. :p * Examine the (N-th) previous file from the command line.
  71. :x * Examine the first (or N-th) file from the command line.
  72. :d Delete the current file from the command line list.
  73. = ^G :f Print current file name.
  74. ---------------------------------------------------------------------------
  75. the (N-th) open bracket in the top line.
  76. MISCELLANEOUS COMMANDS
  77. -<flag> Toggle a command line option [see OPTIONS below].
  78. --<name> Toggle a command line option, by name.
  79. _<flag> Display the setting of a command line option.
  80. __<name> Display the setting of an option, by name.
  81. +cmd Execute the less cmd each time a new file is examined.
  82. !command Execute the shell command with $SHELL.
  83. |Xcommand Pipe file between current pos & mark X to shell command.
  84. v Edit the current file with $VISUAL or $EDITOR.
  85. V Print version number of "less".
  86. ---------------------------------------------------------------------------
  87. OPTIONS
  88. Most options may be changed either on the command line,
  89. or from within less by using the - or -- command.
  90. Options may be given in one of two forms: either a single
  91. character preceded by a -, or a name preceded by --.
  92. -? ........ --help
  93. -a ........ --search-skip-screen
  94. Search skips current screen.
  95. -A ........ --SEARCH-SKIP-SCREEN
  96. Search starts just after target line.
  97. -b [N] .... --buffers=[N]
  98. Number of buffers.
  99. -B ........ --auto-buffers
  100. Don't automatically allocate buffers for pipes.
  101. -c -C .... --clear-screen --CLEAR-SCREEN
  102. Repaint by clearing rather than scrolling.
  103. -d ........ --dumb
  104. Dumb terminal.
  105. -D [xn.n] . --color=xn.n
  106. Set screen colors. (MS-DOS only)
  107. -e -E .... --quit-at-eof --QUIT-AT-EOF
  108. Quit at end of file.
  109. -f ........ --force
  110. Force open non-regular files.
  111. -F ........ --quit-if-one-screen
  112. Quit if entire file fits on first screen.
  113. -g ........ --hilite-search
  114. Display help (from command line).
  115. -G ........ --HILITE-SEARCH
  116. Don't highlight any matches for searches.
  117. --old-bot
  118. Revert to the old bottom of screen behavior.
  119. -h [N] .... --max-back-scroll=[N]
  120. Backward scroll limit.
  121. -i ........ --ignore-case
  122. Ignore case in searches that do not contain uppercase.
  123. -I ........ --IGNORE-CASE
  124. Ignore case in all searches.
  125. -j [N] .... --jump-target=[N]
  126. Screen position of target lines.
  127. -J ........ --status-column
  128. Display a status column at left edge of screen.
  129. -k [file] . --lesskey-file=[file]
  130. Use a lesskey file.
  131. -K --quit-on-intr
  132. Exit less in response to ctrl-C.
  133. -L ........ --no-lessopen
  134. Ignore the LESSOPEN environment variable.
  135. -m -M .... --long-prompt --LONG-PROMPT
  136. Set prompt style.
  137. -n ........ --line-numbers
  138. -N ........ --LINE-NUMBERS
  139. Use line numbers.
  140. -o [file] . --log-file=[file]
  141. Copy to log file (standard input only).
  142. -O [file] . --LOG-FILE=[file]
  143. Copy to log file (unconditionally overwrite).
  144. -p [pattern] --pattern=[pattern]
  145. Start at pattern (from command line).
  146. -P [prompt] --prompt=[prompt]
  147. Define new prompt.
  148. -q -Q .... --quiet --QUIET --silent --SILENT
  149. Quiet the terminal bell.
  150. -r -R .... --raw-control-chars --RAW-CONTROL-CHARS
  151. Output "raw" control characters.
  152. -s ........ --squeeze-blank-lines
  153. Squeeze multiple blank lines.
  154. -S ........ --chop-long-lines
  155. Chop (truncate) long lines rather than wrapping.
  156. -t [tag] .. --tag=[tag]
  157. Find a tag.
  158. -T [tagsfile] --tag-file=[tagsfile]
  159. Use an alternate tags file.
  160. -u -U .... --underline-special --UNDERLINE-SPECIAL
  161. -V ........ --version
  162. Display the version number of "less".
  163. -w ........ --hilite-unread
  164. Highlight first new line after forward-screen.
  165. -W ........ --HILITE-UNREAD
  166. Highlight first new line after any forward movement.
  167. -x [N[,...]] --tabs=[N[,...]]
  168. Set tab stops.
  169. -X ........ --no-init
  170. Don't use termcap init/deinit strings.
  171. -y [N] .... --max-forw-scroll=[N]
  172. Forward scroll limit.
  173. -z [N] .... --window=[N]
  174. Set size of window.
  175. -" [c[c]] . --quotes=[c[c]]
  176. Set shell quote characters.
  177. -~ ........ --tilde
  178. Don't display tildes after end of file.
  179. -# [N] .... --shift=[N]
  180. Horizontal scroll amount (0 = one half screen width)
  181. ........ --no-keypad
  182. Don't send termcap keypad init/deinit strings.
  183. ........ --follow-name
  184. The F command changes files if the input file is renamed.
  185. ........ --use-backslash
  186. Subsequent options use backslash as escape char.
  187. ---------------------------------------------------------------------------
  188. LINE EDITING
  189. These keys can be used to edit text being entered
  190. on the "command line" at the bottom of the screen.
  191. RightArrow ESC-l Move cursor right one character.
  192. LeftArrow ESC-h Move cursor left one character.
  193. ctrl-RightArrow ESC-RightArrow ESC-w Move cursor right one word.
  194. ctrl-LeftArrow ESC-LeftArrow ESC-b Move cursor left one word.
  195. HOME ESC-0 Move cursor to start of line.
  196. END ESC-$ Move cursor to end of line.

5.2、应用

  1. enfdieogjidjfdgj
  2. dffd12487594
  3. iehgjh5934785
  4. f84thifkjgh8934th+i49/GU84HG
  5. (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  6. HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  7. IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  8. 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2] Q
  9. As M=-PKGMV TUHG9U=] [FL';V,C U43JGBN GJNFSKDL,1 20 R =ITUT950JGT
  10. R
  11. Q03-TJU5INOUHW034H
  12. ~
  13. ~
  14. ~
  15. ~
  16. ~
  17. ~
  18. ~
  19. ~
  20. ~
  21. ~
  22. ~
  23. ~
  24. (END)

六、head 取出文件前面几行

语法:

head [-n number] 文件  选项与参数:
  • -n :后面接数字,代表显示几行的意思
  • 默认的情况中,显示前面 10 行!若要显示前 20 行,就得要这样:

6.1、head --help

  1. [user@localhost ~]$ head --help
  2. 用法:head [选项]... [文件]...
  3. Print the first 10 lines of each FILE to standard output.
  4. With more than one FILE, precede each with a header giving the file name.
  5. With no FILE, or when FILE is -, read standard input.
  6. Mandatory arguments to long options are mandatory for short options too.
  7. -c, --bytes=[-]K print the first K bytes of each file;
  8. with the leading '-', print all but the last
  9. K bytes of each file
  10. -n, --lines=[-]K print the first K lines instead of the first 10;
  11. with the leading '-', print all but the last
  12. K lines of each file
  13. -q, --quiet, --silent 不显示包含给定文件名的文件头
  14. -v, --verbose 总是显示包含给定文件名的文件头
  15. --help 显示此帮助信息并退出
  16. --version 显示版本信息并退出
  17. K 后面可以跟乘号:
  18. b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
  19. GB 1000*1000*1000, G 1024*1024*1024, 对于T, P, E, Z, Y 同样适用。
  20. GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
  21. 请向<http://translationproject.org/team/zh_CN.html> 报告head 的翻译错误
  22. 要获取完整文档,请运行:info coreutils 'head invocation'
  23. [user@localhost ~]$

6.2、应用

  1. [user@localhost ~]$ head tr
  2. enfdieogjidjfdgj
  3. dffd12487594
  4. iehgjh5934785
  5. f84thifkjgh8934th+i49/GU84HG
  6. (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  7. HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  8. IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  9. 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2] Q
  10. As M=-PKGMV TUHG9U=] [FL';V,C U43JGBN GJNFSKDL,1 20 R =ITUT950JGT
  11. R

 

七、tail 取出文件后面几行

语法:

tail [-n number] 文件
选项与参数:

  • -n :后面接数字,代表显示几行的意思
  • -f :表示持续侦测后面所接的档名,要等到按下[ctrl]-c才会结束tail的侦测

7.1、tail --help

  1. [user@localhost ~]$ head --help
  2. 用法:head [选项]... [文件]...
  3. Print the first 10 lines of each FILE to standard output.
  4. With more than one FILE, precede each with a header giving the file name.
  5. With no FILE, or when FILE is -, read standard input.
  6. Mandatory arguments to long options are mandatory for short options too.
  7. -c, --bytes=[-]K print the first K bytes of each file;
  8. with the leading '-', print all but the last
  9. K bytes of each file
  10. -n, --lines=[-]K print the first K lines instead of the first 10;
  11. with the leading '-', print all but the last
  12. K lines of each file
  13. -q, --quiet, --silent 不显示包含给定文件名的文件头
  14. -v, --verbose 总是显示包含给定文件名的文件头
  15. --help 显示此帮助信息并退出
  16. --version 显示版本信息并退出
  17. K 后面可以跟乘号:
  18. b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
  19. GB 1000*1000*1000, G 1024*1024*1024, 对于T, P, E, Z, Y 同样适用。
  20. GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
  21. 请向<http://translationproject.org/team/zh_CN.html> 报告head 的翻译错误
  22. 要获取完整文档,请运行:info coreutils 'head invocation'
  23. [user@localhost ~]$ head tr
  24. enfdieogjidjfdgj
  25. dffd12487594
  26. iehgjh5934785
  27. f84thifkjgh8934th+i49/GU84HG
  28. (OLK34]T=P'KLMVGHT49POJT825-5GH9UOFKD\
  29. HG8347T2938THNVRGJUIG+0))+____BJHSKFDNBREU3<F8>5<F7><F8><F2><F3>B
  30. IUT948RNVB<F7><F8><F3>3-POJEVUY5498
  31. 908I4ONJRK B10[OQ;M V-2PFJOVM K9JPIVM K4=2] Q
  32. As M=-PKGMV TUHG9U=] [FL';V,C U43JGBN GJNFSKDL,1 20 R =ITUT950JGT
  33. R
  34. [user@localhost ~]$ tail --help
  35. 用法:tail [选项]... [文件]...
  36. Print the last 10 lines of each FILE to standard output.
  37. With more than one FILE, precede each with a header giving the file name.
  38. With no FILE, or when FILE is -, read standard input.
  39. Mandatory arguments to long options are mandatory for short options too.
  40. -c, --bytes=K output the last K bytes; or use -c +K to output
  41. bytes starting with the Kth of each file
  42. -f, --follow[={name|descriptor}]
  43. output appended data as the file grows;
  44. an absent option argument means 'descriptor'
  45. -F same as --follow=name --retry
  46. -n, --lines=K output the last K lines, instead of the last 10;
  47. or use -n +K to output starting with the Kth
  48. --max-unchanged-stats=N
  49. with --follow=name, reopen a FILE which has not
  50. changed size after N (default 5) iterations
  51. to see if it has been unlinked or renamed
  52. (this is the usual case of rotated log files);
  53. with inotify, this option is rarely useful
  54. --pid=PID with -f, terminate after process ID, PID dies
  55. -q, --quiet, --silent never output headers giving file names
  56. --retry keep trying to open a file if it is inaccessible
  57. -s, --sleep-interval=N with -f, sleep for approximately N seconds
  58. (default 1.0) between iterations;
  59. with inotify and --pid=P, check process P at
  60. least once every N seconds
  61. -v, --verbose always output headers giving file names
  62. --help 显示此帮助信息并退出
  63. --version 显示版本信息并退出
  64. If the first character of K (the number of bytes or lines) is a '+',
  65. print beginning with the Kth item from the start of each file, otherwise,
  66. print the last K items in the file. K may have a multiplier suffix:
  67. b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
  68. GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.
  69. 如果您希望即时追查一个文件的有效名称而非描述内容(例如循环日志),默认
  70. 的程序动作并不如您所愿。在这种场合可以使用--follow=name 选项,它会使
  71. tail 定期追踪打开给定名称的文件,以确认它是否被删除或被其它某些程序重新创建过。
  72. GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
  73. 请向<http://translationproject.org/team/zh_CN.html> 报告tail 的翻译错误
  74. 要获取完整文档,请运行:info coreutils 'tail invocation'
  75. [user@localhost ~]$

7.2、应用

  1. [user@localhost ~]$ tail -n 3 tr
  2. As M=-PKGMV TUHG9U=] [FL';V,C U43JGBN GJNFSKDL,1 20 R =ITUT950JGT
  3. R
  4. Q03-TJU5INOUHW034H
  5. [user@localhost ~]$ tail -n 1 tr
  6. Q03-TJU5INOUHW034H

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/49188
推荐阅读
相关标签
  

闽ICP备14008679号