grep :檢視文本檔案内容,顯示包含指定“字元串”的行。
格式:grep [選項] ‘比對字元串’ 文本檔案
例: grep ' root' /etc/passwd
grep -i 'Root' /etc/passwd 忽略大小寫
grep -v 'root' /etc/passwd 取反,不包含
grep '^root' /etc/passwd 以字元串root開頭
grep 'root$' /etc/passwd 以字元串root結尾
grep -v '^$' /etc/passwd 去除空行的顯示
find:按條件查找
根據預設的條件遞歸查找對應檔案
格式: find [目錄] [條件]
常用條件表示:
-type 類型(f檔案,d目錄,l快捷方式)
-name "文檔名稱"
-size + 檔案大小(k,M,G)
-user 使用者名
-mtime + -修改天數
例:find /boot -type f
find /boot -name "passwd"
find /boot -name "install*" -type d
find /boot -name "*.txt" -type f -size + 10M
find /var/log/ -mtime +1000 #1000天之前
使用find指令的-exec操作
格式:find -exec 處理指令 {} \;
例: find / -user xixi -type f -exec cp -r {}/root/ \;
找到根下的使用者xixi檔案複制到/root下
wc -l 檔案的絕對路徑 統計檔案有多少行
例: 1. 請統計Linux一共有多少使用者?
wc -l /etc/passwd
2.統計/etc目錄下,以".conf"結尾的檔案有多少個?(不包含子目錄)
ls -l /etc/*.conf | wc -l
3.統計/etc目錄下,以".conf"結尾的檔案有多少個?(包含子目錄)
find /etc -name "*.conf" | wc -l
cat 适合檢視内容較多的
head -n 看頭幾行
tail -n 看尾幾行
正規表達式:用描述的語言去表達心中所想。
檢視網絡連結資訊
netstat -anptu
-a: 列出所有的程序
-n: 以數字的形式顯示
-p: 程序名稱及PID資訊
-t: tcp連接配接
-u: udp連接配接
曆史指令
管理/調用曾經執行過的指令
– histroy: 檢視曆史指令清單
– history -c: 清空曆史指令
– !n: 執行指令曆史中的第n條指令
– !str: 執行最近一次以str開頭的曆史指令
曆史指令
管理/調用曾經執行過的指令
histroy 檢視曆史指令清單
histroy -c 清空曆史指令
!n:執行指令曆史中的n條指令
!str:執行最近一次以str開頭的曆史指令
調整曆史指令的數量:
vim /etc/profile
HISTSIZE=1000 預設記錄1000條
本文轉自夜流璃雨 51CTO部落格,原文連結:http://blog.51cto.com/13399294/1980135,如需轉載請自行聯系原作者