Linux??find?????÷????
???????????? ???????[ 2017/4/21 11:45:30 ] ?????????????? Linux
????·find path -option [ -print ] [ -exec -ok command ] {} ;
????find????????????
????pathname: find?????????????·??????????.??????????????/?????????????
????-print?? find????????????????????????
????-exec?? find??????????????иò???????????shell???????????????’command’ { } ;?????{ }?????????
????-ok?? ??-exec??????????????????????????????????иò???????????shell????????????????????????????????????????????????С?
????#-print ???????????????????????
????#-exec command {} ; —–???鵽????????command??????{} ?? ;????п??
????#-ok ??-exec?????????????????????
????????find . -name .svn | xargs rm -rf
====================================================
-name filename #???????filename?????
-perm #??????????????
-user username #???????????????
-group groupname #??????????
-mtime -n +n #???????????????????????-n?n???????+n?n?????
-atime -n +n #????????????????GIN: 0px”>
-ctime -n +n #???????????????????????-n?n???????+n?n?????
-nogroup #??????Ч???????????????????????/etc/groups?в?????
-nouser #??????Ч????????????????????????/etc/passwd?в???
-newer f1 !f2 ???????-n?n???????+n?n?????
-ctime -n +n #???????????????????????-n?n???????+n?n?????
-nogroup #??????Ч???????????????????????/etc/groups?в?????
-nouser #??????Ч????????????????????????/etc/passwd?в???
-newer f1 !f2 #?????????f1?μ???f2??????
-type b/d/c/p/l/f #??????豸??????????豸??????????????????????
-size n[c] #?鳤???n??[??n???]?????
-depth #??????????????????в???????
-fstype #?????????f1?μ???f2??????
-type b/d/c/p/l/f #??????豸??????????豸??????????????????????
-size n[c] #?鳤???n??[??n???]?????
-depth #??????????????????в???????
-fstype #??λ??????????????е????????Щ?????????????? ??/etc/fstab?????
-mount #????????????????mount??
-follow #????????????????????????????????????
-cpio %; #??λ??????????????е????????Щ?????????????? ??/etc/fstab?????
-mount #????????????????mount??
-follow #????????????????????????????????????
-cpio #????????????cpio??????????????????豸??
=====================================================
$find ~ -name “*.txt” -print #??$HOME?в?.txt????????
$find . -name “*.txt” -print
$find . -name “[A-Z]*” -print #?????д???????????
$find /etc -name “host*” -print #????host????????
$find . -name “[a-z][a-z][0–9][0–9].txt” -print #????????Сд?????????????????txt???
$find . -perm 755 -print
$find . -perm -007 -exec ls -l {} ; #??????????????д??е?????-perm 777
$find . -type d -print
$find . ! -type d -print
$find . -type l -print
$find . -size +1000000c -print #?鳤?????1Mb?????
$find . -size 100c -print # ?鳤???100c?????
$find . -size +10 -print #?鳤???????????10????????1??=512????
$cd /
$find etc home apps -depth -print | cpio -ivcdC65536 -o /dev/rmt0
$find /etc -name “passwd*” -exec grep “cnscn” {} ; #????????cnscn???
$find . -name “yao*” | xargs file
$find . -name “yao*” | xargs echo “” > /tmp/core.log
$find . -name “yao*” | xargs chmod o-w
======================================================
find -name april* ???????2?????april????????
find -name april* fprint file ???????2?????april?????????????????????file??
find -name ap* -o -name may* ??????ap??may????????
find /mnt -name tom.txt -ftype vfat ??/mnt?2????????tom.txt??????????? ? vfat?????
find /mnt -name t.txt ! -ftype vfat ??/mnt?2????????tom.txt??????????? ??? vfat?????
find /tmp -name wa* -type l ??/tmp?2??????wa??????????????????????
find /home -mtime -2 ??/home?2?????????????????
find /home -atime -1 ??1????????????????
find /home -mmin +60 ??/home?2?60???????????????
find /home -amin +30 ???30?????????????????
find /home -newer tmp.txt ??/home?2????????tmp.txt???????????
find /home -anewer tmp.txt ??/home?2???????tmp.txt???????????
find /home -used -2 ?г????????????????????2???????????????????
find /home -user cnscn ?г?/home???????????cnscn?????????
find /home -uid +501 ?г?/home?????????????????501?????????
find /home -group cnscn ?г?/home?????cnscn?????????
find /home -gid 501 ?г?/home????id?501?????????
find /home -nouser ?г?/home??????????????????????
find /home -nogroup ?г?/home????????????????????
find /home -name tmp.txt -maxdepth 4 ?г?/home???tmp.txt ????????3??
find /home -name tmp.txt -mindepth 3 ???2?????
find /home -empty ?????С?0??????????
find /home -size +512k ?????512k?????
find /home -size -512k ??С??512k?????
find /home -links +2 ?????????????2?????????
find /home -perm 0700 ??????700?????????
find /tmp -name tmp.txt -exec cat {} ;
find /tmp -name tmp.txt -ok rm {} ;
find / -amin -10 # ?????????к?10???????????
find / -atime -2 # ?????????к?48С?????????
find / -empty # ??????????????????????????
find / -group cat # ?????????????? groupcat?????
find / -mmin -5 # ?????????к?5???????????????
find / -mtime -1 #?????????к?24С????????????
find / -nouser #??????????????????????????
find / -user fred #??????????????FRED???????????
?????鵱????μ???????????
????# find . -type f -exec ls -l {} ;
????-rw-r–r– 1 root root 34928 2003-02-25 ./conf/httpd.conf
????-rw-r–r– 1 root root 12959 2003-02-25 ./conf/magic
????-rw-r–r– 1 root root 180 2003-02-25 ./conf.d/README
?????鵱????μ?????????????????- e x e c????????ls -l?????????г?
????=================================================
??????/ l o g s???в???????????5????????????????????
????$ find logs -type f -mtime +5 -exec -ok rm {} ;
????=================================================
????????????????????
????[root@book class]# find ./ -mtime -1 -type f -exec ls -l {} ;
????=================================================
??????????????????????
????[root@book class]# find ./ -mtime -1 -type f -ok ls -l {} ;
????< ls … ./classDB.inc.php > ? y
????-rw-r–r– 1 cnscn cnscn 13709 1?? 12 12:22 ./classDB.inc.php
????[root@book class]# find ./ -mtime -1 -type f -ok ls -l {} ;
????< ls … ./classDB.inc.php > ? n
????[root@book class]#
????=================================================
?????????????awk?????
????[root@book class]# who | awk ’{print $1″ ”$2}’
????cnscn pts/0
????=================================================
????awk—grep—sed
????[root@book class]# df -k | awk ‘{print $1}’ | grep -v ’none’ | sed s”//dev///g”
?????????
????sda2
????sda1
????[root@book class]# df -k | awk ‘{print $1}’ | grep -v ’none’
?????????
????/dev/sda2
????/dev/sda1
????1)
????A) find /tmp -name “*.h” | xargs -n50 grep SYSCALL_VECTOR
????B) grep SYSCALL_VECTOR /tmp/*.h | cut -d’:’ -f1| uniq > filename
????C) find /tmp -name “*.h” -exec grep “SYSCALL_VECTOR” {} ; -print
????2)find / -name filename -exec rm -rf {} ;
????find / -name filename -ok rm -rf {} ;
????3)?????????????д???3M???????
????find . -size +3000k -exec ls -ld {} ;
????4)??find?????????????????????
????find *.c -exec cp ‘{}’ /tmp ‘;’
????????????????????????cpio???????????????????
????find dir -name filename -print | cpio -pdv newdir
????5)???? 2004-11-30 16:36:37???????????
????# A=`find ./ -name “*php”` | ls -l –full-time $A 2>/dev/null | grep “2004-11-30 16:36:37”
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11