Linux 150命令之查看文件及内容处理命令 cat tac less head tail cut


cat 查看文件内容

  1. [root@mysql tmp]# cat 2.txt
  2. 1234

-n 查看行号

  1. [root@mysql tmp]# cat -n 2.txt
  2.      1 1234
  3.      2 1
  4.      3 2
  5.      4 3
  6.      5 4
  7.      6 5

tac 倒过来显示文件内容

  1. [root@mysql tmp]# tac 2.txt
  2. 5
  3. 4
  4. 3
  5. 2
  6. 1
  7. 1234

less 分页显示文件内容

  1. history | less
  2. 87 ls
  3.    88 cd /class
  4.    89 ls
  5.    90 cd 01
  6.    91 ls
  7.    92 vim n
  8.    93 vim number.py
  9.    94 python
  10.    95 ls
  11.    96 vim number.py
  12.    97 vim age.py
  13.    98 python age.py
  14.    99 vim age.py
  15.   100 python age.py
  16.   101 vim age.py
  17.   102 python age.py
  18.   103 vim age.py
  19.   104 python age.py

head 取文件前几行

-n* 取文件前*行 默认取10行

  1. [root@mysql tmp]# head -n3 2.txt
  2. 1234
  3. 1
  4. 2

tail 取文件后几行

-n* 取文件后*行

  1. [root@mysql tmp]# tail -n2 2.txt
  2. 4
  3. 5

Cut

取列

-d 指定分隔符

-f 取列

-f3,5 取第三列和第五列

-f3-5 取第三列到第五列

  1. [root@mysql tmp]# cat 3.txt
  2. i am love,oldboy and oldgril id
  3. [root@mysql tmp]# cut -d "" -f2,4 3.txt
  4. am and


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM