find命令
find 命令用于查找檔案或目錄
語法格式:
find ./ -type f -name ‘檔案名’
引數依次是:find命令,這里的./指的是當前路徑,-type是選擇檔案型別,檔案型別可以是 f 、d、 l,f是檔案型別,d是目錄型別,l是鏈接型別等,-name 按照名稱查找,檔案名稱要加引號,
-type #按照型別查找
? find ./ -type f # 查找當前目錄 并且顯示隱藏檔案 默認顯示目錄及目錄以下所有符合的檔案
-name #按照名稱查找
? find ./ -type f -name "1.txt" # 按照名稱查找
? find ./ -type f -name "*.txt" # 匹配以.txt結尾的檔案
? find ./ -type f -name "1.t?t" # 通配符匹配 ?代表任意單個字符 大部分命令都支持
?
-size # 按照大小查找 k M G
find ./ -size +50M
find ./ -size +50M -size -100M # 并且關系 查找檔案大于50 并且小于100
? 查找大于80并且小于90的檔案
? find ./ -type f -size +80M -size -90M
-maxdepth # 按照深度等級查找
find ./ -maxdepth 1 -size +50M # 查找1及目錄大于50M的檔案
? find ./ -maxdepth 2 -size +50M # 查找2及目錄大于50M的檔案
?
find查找到的檔案 如何cp rm move
cp 方法1: cp
[root@oldboyedu ~]# find ./ -type f -name "test.sh"|xargs -i cp {} /opt
方法2: cp
[root@oldboyedu ~]# find ./ -type f -name "test.sh" -exec cp {} /tmp \;
方法3: cp
[root@oldboyedu ~]# cp `find ./ -type f -name "test.sh"` /etc/
mv
方法1:mv
[root@oldboyedu ~]# find ./ -type f -name "test.sh"|xargs -i mv {} /opt
方法2:mv
[root@oldboyedu ~]# find /opt -size +50M -exec mv {} ./ \;
方法3:mv
[root@oldboyedu ~]# mv `find ./ -type f -name "test.sh"` /opt
在find中所有的別名失效
[root@oldboyedu ~]# find ./ -name "test.avi"|xargs ll
xargs: ll: No such file or directory
[root@oldboyedu ~]# find ./ -name "test.avi"|xargs ls -l
-rw-r--r--. 1 root root 5 Nov 5 10:35 ./test.avi
find中的rm 不會提示互動資訊 慎用
[root@oldboyedu ~]# find ./ -name "test.avi"
./test.avi
[root@oldboyedu ~]# find ./ -name "test.avi"|xargs rm
[root@oldboyedu ~]# ll test.avi
ls: cannot access test.avi: No such file or directory
?
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/211190.html
標籤:Linux
