视窗
loading...
您现在的位置:首页 > IT认证 > Linux认证 >

Linuxfind命令用法小结


find是个使用频率比较高的命令。常常用它在系统特定目录下,查找具有某种特征「名字类型属主权限等」的文件。

  find命令的格式: find  [-path ……] -options [-print -exec -ok] path:要查找的目录路径。

  ~ 表示$HOME目录。 表示当前目录/ 表示根目录-print :表示将结果输出到标准输出-exec :对匹配的文件执行该参数所给出的shell命令。形式为 command  {} \; ,注意{}与\; 之间有空格-ok :与-exec作用相同,区别在于,在执行命令之前,都会给出提示,让用户确认是否执行

  options常用的有下选项:-name 按照名字查找-perm 安装权限查找-prune 不再当前指定的目录下查找-user 文件属主来查找-group 所属组来查找-nogroup 查找无有效所属组的文件-nouser 查找无有效属主的文件-type 按照文件类型查找下面通过一些简单的例子来介绍下find的常规用法:

  1、按名字查找

  在当前目录及子目录中,查找大写字母开头的txt文件

  view plain [root@localhost ~]# find . -name '[A-Z]*.txt' -print

  在/etc及其子目录中,查找host开头的文件

  view plain [root@localhost ~]# find /etc -name 'host*' -print

  在$HOME目录及其子目录中,查找所有文件

  view plain [root@localhost ~]# find ~ -name '*' -print在当前目录及子目录中,查找不是out开头的txt文件

  view plain [root@localhost .code]# find . -name "out*" -prune -o -name "*.txt" -print

  2、按目录查找

  在当前目录除aa之外的子目录内搜索 txt文件

  view plain [root@localhost .code]# find . -path "./aa" -prune -o -name "*.txt" -print

  在当前目录及除aa和bb之外的子目录中查找txt文件

  view plain [root@localhost .code]# find . \( -path "./aa" -o -path "./bb" \) -prune -o -name "*.txt" -print

  在当前目录,不再子目录中,查找txt文件

  view plain [root@localhost .code]# find .  ! -name "." -type d -prune -o -type f -name "*.txt" -print 3、按权限查找

  在当前目录及子目录中,查找属主具有读写执行,其他具有读执行权限的文件

  view plain [root@localhost ~]# find . -perm 755 -print

  4、按类型查找

  在当前目录及子目录下,查找符号链接文件

  view plain [root@localhost .code]# find . -type l -print

  5、按属主及属组

  查找属主是www的文件

  view plain [root@localhost .code]# find / -user www -type f -print

  查找属主被删除的文件view plain [root@localhost .code]# find /  -nouser -type f -print

  查找属组mysql的文件

  view plain [root@localhost .code]# find /  -group mysql -type f  -print

  查找用户组被删掉的文件

  view plain [root@localhost .code]# find /  -nogroup -type f  -print

  6、按时间查找

  查找2天内被更改过的文件

  view plain [root@localhost .code]# find . -mtime -2 -type f -print

  查找2天前被更改过的文件

  view plain [root@localhost .code]# find . -mtime +2 -type f -print

  查找一天内被访问的文件

  view plain [root@localhost .code]# find . -atime -1 -type f -print

  查找一天前被访问的文件

  view plain [root@localhost .code]# find . -atime +1 -type f -print

  查找一天内状态被改变的文件

  view plain [root@localhost .code]# find . -ctime -1 -type f -print

  查找一天前状态被改变的文件

  view plain [root@localhost .code]# find . -ctime +1 -type f -print

  查找10分钟以前状态被改变的文件view plain [root@localhost .code]# find . -cmin +10 -type f -print

  7、按文件新旧

  查找比aa.txt新的文件

  view plain [root@localhost .code]# find . -newer "aa.txt"  -type f -print

  查找比aa.txt旧的文件

  view plain [root@localhost .code]# find . ! -newer "aa.txt"  -type f -print

  查找比aa.txt新,比bb.txt旧的文件

  view plain [root@localhost .code]# find . -newer 'aa.txt' ! -newer 'bb.txt' -type f -print

  8、按大小查找

  查找超过1M的文件

  view plain [root@localhost .code]# find / -size +1M -type f -print

  查找等于6字节的文件

  view plain [root@localhost .code]# find . -size 6c -print

  查找小于32k的文件

  view plain [root@localhost .code]# find . -size -32k -print

  9、执行命令

  查找del.txt并删除,删除前提示确认

  view plain [root@localhost .code]# find . -name 'del.txt' -ok rm {} \;

  查找aa.txt 并备份为aa.txt.bak

  view plain [root@localhost .code]# find . -name 'aa.txt' -exec cp {} {}.bak \;

闂侀潧妫岄崑锟�

闂侀潧妫岄崑锟�

闂侀潧妫欓崝鏇㈠储閵堝洦瀚婚柨婵嗘嫅缁憋綁鏌¢崟顐︻€楅柟铚傚嵆閹囧醇閻斿摜绉柣鐘叉搐閻°劌危閹达箑违闁跨噦鎷�
闂佸搫鐗滈崜娑㈡偟椤栫偞鐒鹃柕濞垮劚閻庤菐閸ワ絽澧插ù鐓庢嚇瀵爼濡烽敂鍓у煃婵炲瓨绮岀花鑲╄姳娴煎瓨鍤傞柡鍐ㄥ€荤粔褰掓煥濞戣櫕瀚�闁诲海鏁搁、濠偯归崱妯诲闁伙絽鏈悾鍗炃庨崶锝呭⒉濞寸厧鎳橀獮瀣箣濠婂嫮鎷ㄩ梺鍛婃⒐缁嬫帡鎯囨导鏉戝唨闁搞儯鍔嶉~鏍庨崶锝呭⒉濞寸厧鎳橀幆鍐礋椤愩垺鐦旀繝銏f硾鐎氬摜妲愰敓锟�闂佺懓鐡ㄩ崹鍐测堪閹寸姳鐒婂┑鐘叉搐濞呫垹霉閿濆棛鐭庨柍褜鍓欓幊鎰枔閹达附鍋嬮柛顐ゅ枑缂嶁偓闂佹垝鐒﹂妵鐐电礊閺冨牆绾ч柛鎰硶缁€锟�闁诲簼绲婚~澶愬垂濠婂嫮顩锋い鎺戝暞缁侇噣寮堕悙鍨珪婵炲牊鍨剁粚閬嶅焺閸愌呯婵犵鈧啿鈧懓锕㈡担鍓插殨闁稿本绻嶉崬鎾煙鐎涙ḿ澧繝鈧担鍦懝闁割煈鍋呯紞鈧梺鐟扮摠閻楃偟鎹㈠顑芥灃闁哄洦鐭换鍡涙煙椤撗冪仴妞ゆ洦鍓熷畷锝嗙節閸愨晩妲梺鑹伴哺濮婂鏌堥幘顔肩闁瑰瓨绮嶇划锕傛煥濞戞ɑ婀版繝鈧幍顔惧崥婵炲棗娴风粣妤冪磼閺傛鍎忕€规挸妫濆畷姘舵偐缂佹ḿ褰戦梺鎸庡喕閹凤拷闁诲海鏁搁幊鎾舵暜椤愶箑绀嗘繛鎴灻弫鍫曟倵绾拋娼愰柛銊︾矋缁傛帡顢楁担绋啃梺瑙勬緲缁绘垿寮鐣岊浄婵せ鍋撻柍褜鍓欓崐鍝ョ礊鐎n喗鍎嶉柛鏇ㄥ帎瑜版帗鐓€妞ゆ帒锕︾粈锟�闂佽壈椴稿濠氭焾閹绢喖妫橀柣鐔稿绾偓闂佹寧绋掑畝鎼佸磻閺嶃劎顩烽柨鐕傛嫹:webmaster@jscj.com闂侀潧妫岄崑鎾绘煟椤厾绁烽柣锔跨矙閺佸秹鏁撻敓锟�4008816886

相关文章

无相关信息
更新时间2022-03-13 11:11:02【至顶部↑】
联系我们 | 邮件: webmaster@jscj.com | 客服热线电话:4008816886(QQ同号) |  濠电儑缍€椤曆勬叏閻愮鍋撻獮鍨仾婵犫偓閸パ屽殫妞ゆ棁顔婄换锟�

付款方式留言簿投诉中心网站纠错二维码手机版

客服电话: