find常用參數
1.find 命令
參數 | 作用 |
---|---|
-name | 查找 |
-user | 文件擁有者 |
-group | 根據文件擁有組 |
-type | 類型 |
-perm | 文件權限 |
-exec | 執行 |
-maxdepth | 最大深度 |
-mindepth | 最小深度 |
-o | 或者 |
-a | 並且 |
-not | 反選 |
2.練習:
- 查找最大深度與最小深度
- 建立一些文件,修改所有人和所有組
- 用戶組
- 結合-o -a -not 使用
- find /mnt -perm
find /mnt -perm 111 | 文件權限爲111 |
---|---|
find /mnt -perm -111(-表示並且) | 文件權限u位有1 G位有1 o位有1 |
find /mnt -perm /111(/表示或者) | 文件案權限u或G或O 含有1 |
理解:111是3個條件,211也是3個條件,311則是4個條件(因爲3=2+1,參考1248),755是7個條件(7=1+2+4;5=1+4)對應下來就是3個+2個+2個=7個條件
- find /mnt -perm /111 -type f -exec chmod ugo-x {} ;
注意:要加";"
[root@rhel8 mnt]# find /mnt -perm -111 -type f -exec chmod ugo-x{} ;
find: missing argument to `-exec'
[root@rhel8 mnt]# find /mnt -perm -111 -type f -exec chmod ugo-x{} \;
{} 表示find命令查找結果 #\是爲了轉譯“;”
- 查看/分區中大於100M的文件