find命令
1.作用
Linux find命令用來在指定目錄下查找文件。任何位于參數之前的字符串都將被視為欲查找的目錄名。如果使用該命令時,不設置任何參數,則find命令將在當前目錄下查找子目錄與文件。并且將查找到的子目錄和文件全部進行顯示。
2.格式:
find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
3.常用參數
find . -type 類型參數
f 普通文件 列出文件 find . -type f
l 符號連接
d 目錄 列出文件夾 find . -type d
c 字符設備
b 塊設備
s 套接字
-pid n : process id 是 n 的文件
查找文件
find ./ -type f
搜索最近1天內被訪問過的所有文件
find . -type f -atime -1
搜索恰好在1天前被訪問過的所有文件
find . -type f -atime 1
搜索超過1天內被訪問過的所有文件
find . -type f -atime +1
搜索訪問時間超過10分鐘的所有文件
find . -type f -amin +10
向下最大深度限制為3
find . -maxdepth 3 -type f
搜索出深度距離當前目錄至少2個子目錄的所有文件
find . -mindepth 2 -type f
查找目錄
find ./ -type d
查找名字為test的文件或目錄
find ./ -name test
-name name, -iname name : 文件名稱符合 name 的文件。iname 會忽略大小寫
打印test文件名后,打印test文件的內容
find ./ -name test.txt -print -exec cat {} ;
不打印test文件名,只打印test文件的內容
find ./ -name test.txt -exec cat {} ;
在特定的目錄下找后綴名為.jar的所有文件
find /home/test -iname *.jar
其他
要列出所有長度為零的文件
find . -empty
查找系統中所有文件長度為0的普通文件,并列出它們的完整路徑:
find / -type f -size 0 -exec ls -l { }
查找前目錄中文件屬主具有讀、寫權限,并且文件所屬組的用戶和其他用戶具有讀權限的文件:
find . -type f -perm 644 -exec ls -l { }
查找文件size小于10M的文件或目錄
find ./ -size -10M
-size n : 文件大小 是 n 單位,b 代表 512 位元組的區塊,c 表示字元數,k 表示 kilo bytes,w 是二個位元組。-type c : 文件類型是 c 的文件。
netstat
1.作用
netstat命令用于顯示與IP、TCP、UDP和ICMP協議相關的統計數據,一般用于檢驗本機各端口的網絡連接情況。netstat是在內核中訪問網絡及相關信息的程序,它能提供TCP連接,TCP和UDP監聽,進程內存管理的相關報告。
2.命令
usage:
netstat [-vWeenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}
netstat [-vWnNcaeol] [<Socket> ...]
netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]
常用組合:
netstat -lntup
說明: l:listening n:num t:tcp u:udp p:process
查看linux所有被占用的端口
netstat -tulnp
可以通過netstat -tulnp | grep 端口號查看當前端口號是否被占用
netstat -tulnp|grep 3306
-t(tcp)只顯示tcp相關的
-u(udp)只顯示udp相關的
-l(listening)只顯示監聽服務的端口
-n(numeric)不解析名稱,能用數字表示的就不用別名(例如:localhost會轉成127.0.0.1)
-p(programs)顯示端口的PID和程序名稱