歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux服務器 >> Linux基礎-文字處理命令匯總

Linux基礎-文字處理命令匯總

日期:2017/3/2 16:31:16   编辑:Linux服務器

  本文將總結如下命令:

  wc: word count

  -l: 僅顯示行數

  -w: 僅顯示字數

  -c: 僅顯示byte大小

  cut:(remove sections from each line of files)從文件的每行裡刪除固定的部分,用於匹配分隔符,然後篩選需要的列內容

  -d: 指定分隔符

  -f: 指定要顯示的字段

  m: 第m列

  m,n: 第m和n列

  m-n: 第m到第n列

  sort 排序

  -f: 忽略字符大小寫

  -t: 指定分隔符

  -k: 指定分隔符的位置號

  -n: 以數值大小進行排序

  -u: 排序後去重

  uniq :(report or omit repeated lines)匯報或者忽略重復行, 容易忽略-c,可以統計重復次數

  練習:

  1、顯示當前系統上每個用戶的shell;

  # cut -d: -f1,7 /etc/passwd

  2、顯示當前系統上所有用戶使用的各種shell;

  # cut -d: -f7 /etc/passwd | sort | uniq

  3、取出/etc/inittab文件的第7行;

  # head -n 7 /etc/inittab | tail -n 1

  4、取出/etc/passwd文件中第7個用戶的用戶名;

  # head -n 7 /etc/passwd | tail -n 1 | cut -d: -f1

  5、統計/etc目錄下以大小寫p開頭的文件的個數;

  # ls -d /etc/[pP]* | wc -l

:完

Copyright © Linux教程網 All Rights Reserved