1. 程式人生 > >查看文件及內容處理命令 cat tac less head tail cut

查看文件及內容處理命令 cat tac less head tail cut

lov oot lac mys root family pan oldboy mil

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

查看文件及內容處理命令 cat tac less head tail cut