ºìÁªLinuxÃÅ»§
Linux°ïÖú

LinuxÖÐfind³£¼ûÓ÷¨Ê¾Àý

·¢²¼Ê±¼ä:2014-07-11 10:08:01À´Ô´:ºìÁª×÷Õß:velcbo
?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 #²éλÓÚijһÀàÐÍÎļþϵͳÖеÄÎļþ£¬ÕâЩÎļþϵͳÀàÐÍͨ³£¿É ÔÚ/etc/fstabÖÐÕÒµ½
-mount #²éÎļþʱ²»¿çÔ½Îļþϵͳmountµã
-follow #Èç¹ûÓöµ½·ûºÅÁ´½ÓÎļþ£¬¾Í¸ú×ÙÁ´½ÓËùÖ¸µÄÎļþ
-cpio %; #²éλÓÚijһÀàÐÍÎļþϵͳÖеÄÎļþ£¬ÕâЩÎļþϵͳÀàÐÍͨ³£¿É ÔÚ/etc/fstabÖÐÕÒµ½
-mount #²éÎļþʱ²»¿çÔ½Îļþϵͳmountµã
-follow #Èç¹ûÓöµ½·ûºÅÁ´½ÓÎļþ£¬¾Í¸ú×ÙÁ´½ÓËùÖ¸µÄÎļþ
-cpio #¶ÔÆ¥ÅäµÄÎļþʹÓÃcpioÃüÁ½«ËûÃDZ¸·Ýµ½´Å´øÉ豸ÖÐ
-prune #ºöÂÔij¸öĿ¼

=====================================================
$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* ÔÚµ±Ç°Ä¿Â¼Ï²éÕÒÒÔapril¿ªÊ¼µÄÎļþ
find -name april* fprint file ÔÚµ±Ç°Ä¿Â¼Ï²éÕÒÒÔapril¿ªÊ¼µÄÎļþ£¬²¢°Ñ½á¹ûÊä³öµ½fileÖÐ
find -name ap* -o -name may* ²éÕÒÒÔap»òmay¿ªÍ·µÄÎļþ
find /mnt -name tom.txt -ftype vfat ÔÚ/mntϲéÕÒÃû³ÆÎªtom.txtÇÒÎļþϵͳÀàÐÍΪvfatµÄÎļþ
find /mnt -name t.txt ! -ftype vfat ÔÚ/mntϲéÕÒÃû³ÆÎªtom.txtÇÒÎļþϵͳÀàÐͲ»ÎªvfatµÄÎļþ
find /tmp -name wa* -type l ÔÚ/tmpϲéÕÒÃûΪwa¿ªÍ·ÇÒÀàÐÍΪ·ûºÅÁ´½ÓµÄÎļþ
find /home -mtime -2 ÔÚ/homeϲé×î½üÁ½ÌìÄڸ͝¹ýµÄÎļþ
find /home -atime -1 ²é1ÌìÖ®ÄÚ±»´æÈ¡¹ýµÄÎļþ
find /home -mmin +60 ÔÚ/homeϲé60·ÖÖÓǰ¸Ä¶¯¹ýµÄÎļþ
find /home -amin +30 ²é×î½ü30·ÖÖÓǰ±»´æÈ¡¹ýµÄÎļþ
find /home -newer tmp.txt ÔÚ/homeϲé¸üÐÂʱ¼ä±Ètmp.txt½üµÄÎļþ»òĿ¼
find /home -anewer tmp.txt ÔÚ/homeÏÂ²é´æÈ¡Ê±¼ä±È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"\t"$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)ÔÚ/tmpÖвéÕÒËùÓеÄ*.h£¬²¢ÔÚÕâЩÎļþÖвéÕÒ¡°SYSCALL_VECTOR"£¬×îºó´òÓ¡³öËùÓаüº¬"SYSCALL_VECTOR"µÄÎļþÃû
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

6)²éÕÒ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"

find ʵÀý
ÒªÔÚ/usr/linuxÖвéÕÒËùÓеÄ*.h£¬²¢ÔÚÕâЩÎļþÖвéÕÒ¡°SYSCALL_VECTOR"£¬×îºó´òÓ¡³öËùÓаüº¬"SYSCALL_VECTOR"µÄÎļþÃû£¬ÓÐÒÔϼ¸ÖÖ·½·¨ÊµÏÖ

find /usr/linux -name "*.h" | xargs -n50 grep SYSCALL_VECTOR
grep SYSCALL_VECTOR /usr/linux/*.h | cut -d¡¯:¡¯ -f1 | uniq > filename
find /usr/linux -name "*.h" -exec grep "SYSCALL_VECTOR" {} \; -print

¡¡¡¡ÎÒÓÃfind / -name filename| rm -rf£¬²»³É¹¦£¬ÇëÎÊΪʲô²»³É¹¦£¿
find / -name filename -exec rm -rf {} \;
find . -name filename |rm -rfÊÔÒ»ÏÂ{} ±íʾÄãÕÒ³öÀ´µÄ½á¹û¡£
\; ÔòÏ൱ÓÚ¡°ÏÜ·¨¡±£¬Ã»Ê²Ã´ËµÍ·£¬¾ÍÊÇÕâô¹æ¶¨µÄ£¬ÔÚ -exec ºóÃæÐèÒªÒ»¸ö±íʾ¸ÃÃüÁîÖÕ½áµÄµÄ·ûºÅ¡£¿ÉÒÔÔÚ man find ÖÐÕÒµ½´ð°¸¡£
ÒªÈÃrmʶ±ðfindµÄ½á¹û£¬ÈçÏ£º
find / -name filename |xargs rm -rf
Ö®ËùÒÔfind . -name filename |rm -rf²»Í¨¹ý£¬ÊÇÒòΪrmÃüÁî²»½ÓÊÜ´Ó±ê×¼ÊäÈë´«¹ýÀ´µÄÖ¸Áî
²éÕÒº¬Ìض¨×Ö·û´®µÄÎļþ
ÀýÈç²éÕÒµ±Ç°Ä¿Â¼Ïº¬ÓÐ"the string you want find¡­"×Ö·û´®µÄÎļþ£º
$find . -type f -exec grep ¡°the string you want find¡­¡± {} ; -print

¡¡¡¡´Ó¸ùĿ¼¿ªÊ¼²étmpfile£¬Ò»µ©²éµ½ÂíÉÏɾ³ý
find / -name "tmpfile" -exec rm {} \;

¡¡¡¡find µÄpermÎÊÌâ
ÇëÎÊÒ»ÏÂÒÔÏÂÃüÁîʲôÒâ˼£¿¹Ø¼üÊÇÄǸöÊý×ÖǰµÄ-£¬ÆäËû¶¼»¹ÖªµÀ
find -name ".*" -perm -007
ÎÒÖªµÀ
find -name ".*" -perm 755
Õâ¸öÊÇÓÃÀ´²éÕÒȨÏÞλΪ755µÄÒþ²ØÎļþ
àÞ£¬¶ÔÁË»¹ÓУ¬ÎÒÉϱߵÄÃüÁʡÂÔÁËfindµÄpathname²ÎÊý findĬÈÏÊDzéÕÒµ±Ç°¹¤×÷Ŀ¼µÄÂð£¿
Èç¹ûÎÒÓà -ok Ìæ´ú -exec, ÄÇô»¹ÐèÒª¼ÓÉÏ {} \; Âð£¿
Õâ¸öÒѾ­Çå³þ£¬ÈÔÈ»ÐèÒª£¬ÒòΪ -ok Ö»ÊÇ -exec µÄÌáʾģʽ£¬ËüÖ»ÊǶàÁËÒ»¸öÈ·ÈϲÙ×÷µÄ²½Öè,¸Õ²ÅûÓжÁ¶®ÄǼ¸¾äEÎĵÄÒâ˼ ºÇºÇ ²»ºÃÒâ˼
-007ÊÇÖ¸²éÕÒËùÓÐÓû§¶¼¿É¶Á¡¢Ð´¡¢Ö´ÐеÄÎļþ£¬ÒªÐ¡ÐÄѽ~~~
½âÊͽâÊÍ£¿
find -name ".*" -perm -007 ºÍ find -name ".*" -perm 777 ÓÐÇø±ðÂð£¿
-007ÊÇÔõôÀ´µÃÄØ£¿
²»¹ýÓÐÒ»¸öÎÊÌâ
ÎÒÓà find . -perm -100 »áÁгöµ±Ç°Ä¿Â¼ . , ÕâÊÇÎªÊ²Ã´ÄØ£¿

ÏÂÃæÒýÓÃÓÉexploverÔÚ 2002/10/01 06:15am ·¢±íµÄÄÚÈÝ£º
-007ÊÇÖ¸²éÕÒËùÓÐÓû§¶¼¿É¶Á¡¢Ð´¡¢Ö´ÐеÄÎļþ£¬ÒªÐ¡ÐÄѽ~~~
-007ÊDzéÕÒº¬ÆäËüÓû§(²»Í¬×é,·ÇÊôÖ÷)¿É¶Á,д,Ö´ÐеÄÎļþ.²¢²»Ò»¶¨ÒªÍ¬×é¿É¶Áд,-ÊÇÖ¸×îÉÙȨÏÞΪ007.
ÏÂÃæÒýÓÃÓÉÒ»¿ÅС°×²ËÔÚ 2002/10/01 10:16am ·¢±íµÄÄÚÈÝ£º
OKÁË£¬ ºÇºÇ
²»¹ýÓÐÒ»¸öÎÊÌâ
ÎÒÓà find . -perm -100 »áÁгöµ±Ç°Ä¿Â¼ . , ÕâÊÇÎªÊ²Ã´ÄØ£¿
ÕâÖÖ·½·¨²»»á׼ȷµÄÕÒ³öĿ¼µÄ. -100ÊÇָȨÏÞÖÁÉÙÊÇÊôÖ÷¿ÉÔËÐÐ.
ÔÚunixϵͳÏÂ,Äã¿ÉÒÔÓµÓжÔĿ¼ÎļþµÄÖ´ÐÐȨÄã²Å¿ÉÒÔ½øÈëÒ»¸öĿ¼.Õâ±ãÊÇĿ¼Îļþ±»ÁгöµÄÔ­Òò.
find . -perm -001 -printÕÒµ½ÍùÍùÊÇĿ¼Îļþ.
ÎÒµÄÒâ˼µ±È»²»ÊÇʹÓÃÕâÖÖ·½·¨À´ÕÒĿ¼£¬Ö»²»¹ý²»Ã÷°×ÆäÖÐµÄ -100 ÒâÒåÁË
ÄÇÒÔ´ËÀàÍÆ£¬ÊDz»ÊÇ -010ÊÇָȨÏÞÖÁÉÙÊÇownerͬ×é¿ÉÖ´ÐеÄÂð£¿Ò²¾ÍÊÇ˵ÆäʵÕâÀïµÄ010ºÍ-ÊÇ·Ö¿ªµÄ£¬-±íʾһ¸öÖÁÉÙµÄÒâ˼£¬¶øÇÒ010²ÅÊÇÕæÕýÓÃÀ´ÃèÊöȨÏÞλµÄ£¿
ÕâÑù×Ó¾ÍÃ÷°×ÁË Ð»Ð»ÄãàÞ

¡¡¡¡½«find³öÀ´µÄ¶«Î÷¿½µ½ÁíÒ»¸öµØ·½?
find *.c -exec cp ¡®{}¡¯ /tmp ¡®;¡¯
Èç¹ûÓÐÌØÊâÎļþ£¬¿ÉÒÔÓÃcpio£¬Ò²¿ÉÒÔÓÃÕâÑùµÄÓï·¨£º
find dir -name filename -print | cpio -pdv newdir

¡¡¡¡ÕÒ³ö´ÅÅÌÖÐij¸ö´óС·¶Î§ÄÚµÄÎļþ
±ÈÈçÒª²éÕÒ´ÅÅÌÖдóÓÚ3MµÄÎļþ£º
find . -size +3000k -exec ls -ld {} ;

¡¡¡¡ÈçºÎÓÃfind²éÕÒijһÌì¸ü¸ÄµÄÎļþ£¿
¿ÉÒÔʹÓÃÕâÒ»ÐÐÃüÁîÀ´ÊµÏÖ£º
A=`find ~ -print` | ls -l -full-time $A 2>/dev/null | grep "Jun 27" | grep 1998

¡¡¡¡Ê¹ÓÃfind ÃüÁî²éÕÒij¸öʱ¼ä¶ÎµÄshellÔõôд¡£±ÈÈç11µãµ½12µãµÄ¡£thanks
´´½¨Ò»¸ö½Å±¾judgetime£¬ÄÚÈÝÈçÏ£º
ls -l $*|awk ¡®{split($8,hour,":");if((hour[1]>23 || hour[1] < 1)&&hour[1]<24)print}¡¯
µ½Òª²éÕÒµÄĿ¼Ï£¬ÔËÐÐ
find ./ -name "*" -exec judgetime {} \;
×¢Òâʱ¼ä¸ñʽΪ£²£´Ð¡Ê±ÖÆ¡£
thank you £¬Èç¹ûÎÒÒª¾«È·µ½·ÖÖÓÄØ
touch -t 04241112 starttemp #¾«È·µ½12·ÖÖÓ
touch -t 04241220 endtemp #½ØÖ¹µ½12µã20
find [dir] -newer starttemp -a ! -newer endtemp -exec ls -l {} \;
£î£å£÷£å£ò£¿
ÄÇ×òÌ죱£²£º£±£°ÎļþÈçºÎÄØ£¿
ÿÌìÖ´ÐеÄʱºò£¬Óõ±ÌìµÄÈÕÆÚºÍʱ¼ä´ÁÌæ»»Ò»Ï²»¾ÍÐÐÁËÂð£¿
ÎÒ²»ÖªµÀËûÊDz»ÊǰÑËùÓеÄ11£º00~12£º00µÄ¶¼ÕÒ³öÀ´£¬ÊDz»ÊÇÖ»Ö´ÐÐÒ»´Î»¹ÊÇÿÌì¶¼Ö´ÐУ¿
ÕâÖÖÇé¿ö°³²ÂÏëÊÇ×Ô¼ºµÄ¶«Î÷·ÅÔÚÄÄÍüÁË£¬Ö»¼ÇµÃµ±Ê±ÊÇÉîÒ¹ÁË¡£
ÓеÀÀí£¡
²»À¢ÊǰßÖñ£¡
²»¹âÖªµÀÔõô½â¾öÎÊÌ⣬»¹ÖªµÀÔÚʲôÇé¿öϳöÏÖÕâÀàÎÊÌ⣬Åå·þÅå·þ£¡
ÎÊÌâÓÖ³öÏÖÁË¡£´´½¨Õâ¸öÎļþµÄʱºò¡£±¾À´Ó¦¸ÃÊÇʱ¼äµÄÒ»À¸ÏÖÔÚдÉÏÁË2002£¬¶ø²»ÊÇ12£º00.
µÈµ½12£º00¹ýÁ˰ɣ¡

¡¡¡¡É¾³ýÖ¸¶¨ÈÕÆÚµÄÎļþ
find ./ -name ÎļþÃû -exec rm -f {} \;
Àý£ºÉ¾³ýµ±Ç°30ÌìÄÚûÓùýµÄÎļþ,ÓÃÈçÏÂÃüÁ
find / -atime +30 -exec rm -f {} \;
ÎÒ×Ô¼ºÊÔ×ÅдÁËһС¶ÎSHELL,Ò²ÓÃll ,grep, rm ¼¸¸öÃüÁÓÃÆðÀ´»¹²îÇ¿ÈËÒâ¡£
¶Ô¹ýÂ˳öÀ´µÄÎļþÃûÁбíÖÐÓÃÁËÒ»¸öFORÓï¾ä£¬ÔÙÖ´ÐÐrm ¡£ÏÖÔÚÎÒÏë°ÑÕâ¶ÎSHELL À©Õ¹Ò»ÏÂÈÃËüÿÌ춨ʱÔËÐн« n ÌìǰµÄÎļþɾµô£¬ÓÐûÓÐÈËÄܸøÎÒһЩÌáʾ£¬Ð»Ð»£¡
»¹ÓиöÎÊÌ⣬¶ÔÓÚÇ°ÃæÄÇλÅóÓÑÌáµ½µÄ"find / -atime +30 -exec rm -f {} \;
"·½·¨£¬ÎÒºÜÔç¾ÍÊÔ¹ý¼¸´Î£¬²»¹ýºÃÏñ¶¼²»Ì«¶Ô£¬²ÎÊý -atime n ÊDzéÕÒnÌìǰ±»·ÃÎʹýµÄÎļþ£¬ÎÒ²»Ã÷°×µÄÊÇÕâÀïµÄʱ¼ä²ÎÕÕµãÊÇʲô£¬ÒÔ¼°Õâ¸önÌìÊÇÔõô¼ÆËãµÄ¡£
ÎÊ Ìâ¶þ¡¢¶ÔÓÚ"ll |cut -f 1" Õâ¸öÃüÁîÎÒÊDz»ÊÇÓôíÁË£¬ÎÒÖ»ÏëÈ¡³ö ll ÖÐÁгöµÄÎļþÃû£¬µ«ÓÃcut -f ÃüÁî×ö²»µ½ £¬ÎÒÖ»ºÃ»»Óà ll |cut -c 59- ÕâÖÖ·½Ê½µÃµ½ÎÒÒªµÄÎļþÃû£¬but it¡¯s a pool idear £¡ÎÒÒ²ÊÔ¹ýÓÃawk £¬ºÃÏñÒ²²»¶Ô£¬¿´¿´´ó¼Ò¿É²»¿ÉÒÔ¸øÎÒһЩССµÄÌáÐÑ£¬TKS SO MUCH
ÎÊÌâÈý¡¢ÈçºÎ¸Ä±ä I½áµã µÄÈÕÆÚ¸ñʽ ÎÒÏÖÔÚµÄϵͳÏÔʾµÄ¸ñʽÊÇ£º
-rw-r--- 1 msahz01 users 2253 2002Äê2ÔÂ 2ÈÕ poheader.i
ÎÒÏë°ÑÕâ»»³É
-rw-rw-rw- 1 house users 2193 Apr 19 2001 hkdisp.p
ÈçºÎ²ÅÄÜ×öµ½Õâµã£¿
awk Ó¦¸Ã¿ÉÒÔ
ll | awk ¡®{print $9}¡¯
ɾ³ý¶àÉÙÌì֮ǰµÄÎļþ
find /yourpath -mtime +31 -exec rm {} \;
find /yourpath -mtime +366 -exec rm {} \;

findÖÐ, -ctime, -mtime¼°Æä-atimeÓкÎÇø±ð

ÇëÎÊ -ctime ºÍ -mtime ÓÐʲô¹ØÏµ ?
Èç¹û¸¸Ä¿Â¼µÄ ctime ¸Ä±ä, ÄÇËüÏÂÃæµÄÎļþµÄ ctime ¾Í»á×Ô¶¯¶¼¸ÄÁËÂð ?
-ctime ºÍ -mtime ,-atime ÕâЩÐÅÏ¢ÊÇ´æÔÚÄĶùÄØ ?

ÎÒÓà -mtime -1 ÕÒµ½ÁËн¨»ò¸ÄµÄÎļþ.
µ«ÔõÑù²ÅÄÜÕÒµ½Ò»ÌìÄÚ mv À´µÄÎļþÄØ( ËüÃǵÄʱ¼äÊÇÔ­ÓеÄʱ¼ä,ÔçÓÚÒ»Ìì ) ?

ÓÃ-newerÑ¡Ïî°¡¡£
Äã¿ÉÒÔÏÈtouchÒ»¸öÄãÏëÒªµÄʱ¼äµÄÎļþÈçÏ£º
$ touch -t 08190800 test
$ ls -l test
-rw-r-r- 1 dba other 0 Aug 19 08:00 test
È»ºó
$ find . -newer test -print
.
./.sh_history
$ ls -l .sh_history
-rw----- 1 dba other 154 Aug 20 17:39 .sh_history

ÓÃtouch¿ÉÒÔд³öÄãÏëÒªµÄÈκÎʱ¼äµÄÎļþ£¬È»ºóÓÃ-newer ,! -newerÑ¡Ïî¼´¿É³É¹¦¡£

1.ctimeº¬inodeÐÅÏ¢Ð޸ĵÄʱ¼ä.mtimeÖ»Ö¸ÎļþÄÚÈݽ¨Á¢»òÐ޸ĵÄʱ¼ä.
2 ²»»á.
3.ÕâЩÐÅÏ¢Ó¦¸ÃÊÇ´æÔÚÎļþϵͳµÄ³¬¼¶¿éÀï.

ÎÒ²éÁËÊé -ctime ÊÇÖ¸ inode µÄ¸Ä±ä(»ò³ÆÎļþµÄ״̬¸Ä±ä).
ÇëÎÊ inode ´æÁËÄÄЩÐÅÏ¢ ?
×öÁËЩС²âÊÔ,-mtime ¸Ä, -ctime Ò»¶¨Ò²¸Ä.
¸ÄÎļþÃû, -ctime Ò²»á¸Ä.
Ë­Äܻشð i-node ´æÁËÄÄЩ¶«Î÷ ?

vi /usr/include/sys/inode.h

°àÖ÷,ÎÒ²»ÄÜ access /usr/include/sys/inode.h .
ÕªÊéÈçÏÂ:
Directories contain directory entries. Each entry contains a file or subdirectory name and an index node reference number (i-node number). To increase speed and enhance use of disk space, the data in a file is stored at various locations in the computer¡¯s memory. The i-node contains the addresses used to locate all the scattered blocks of data associated with a file. The i-node also records other information about the file including time of modification and access, access modes, number of links, file owner, and file type.
¿ÉÎÒ·¢ÏÖ -atime ¸ÄÁË, -ctime »¹Ã»¸Ä. why ?
( ÎÒÏÈ cat Ò»¸ö ASCII Îļþ,ÔÙÓà -atime -1 ÓÐËüÓà -ctime -1 ¾ÓȻûÓÐËü.)
×ÅÆñ²»¸ú inode ÐÅÏ¢¸Ä±ä, ctime ¾Í¸Äì¶ÜÂð?

ÎÒ²»Í¬ÒâÄãÌù³öÀ´µÄÄǶÎÎÄÕÂ,ÕýÈçÎÒÌáµ½µÄÄÇÑù,atime,ctime,mtimeÊǷŵ½³¬¼¶¿éÀï,ÔÚsco unixÏÂÊÇÒ»ÖÖ½ÐstatµÄ½á¹¹.(stat_32),²»Í¬µÄϵͳÎļþϵͳ¿ÉÄܲ»Í¬.
sco ÏÂinodeµÄ½á¹¹ÈçÏÂ:

typedef struct inode
{
struct inode *i_forw; /* inode hash chain */
struct inode *i_back; /* ¡®¡¯ */
struct inode *av_forw; /* freelist chain */
struct inode *av_back; /* ¡®¡¯ */
int *i_fsptr; /* "typeless" pointer to fs dependent */
ino32_t i_number; /* i number, 1-to-1 with dev address */
ushort i_ftype; /* file type = IFDIR, IFREG, etc. */
short i_fstyp; /* File system type */
off_t i_size; /* size of file */
ushort i_uid; /* owner */
ushort i_gid; /* group of owner */
ushort i_flag;
ushort i_want; /* i_flag extension to avoid MP races */
ushort i_count; /* reference count */
short i_nlink; /* directory entries */
dev_t i_rdev; /* Raw device number */
#define i_namtype i_rdev /* i_ftype==IFNAM subtype */
dev_t i_dev; /* device where inode resides */
struct mount *i_mton;/* ptr to mount table entry that */
/* this directory is mounted on */
struct region *i_rp; /* ptr to shared region if any */
struct stdata *i_sp; /* ptr to associated stream */
struct iisem *isem; /* ptr to XENIX semaphores */
struct iisd *isd; /* ptr to XENIX shared data */
} i_un;
#define i_mnton i_un.i_mton /* i_ftype==IFDIR IMOUNT */
#define i_rptr i_un.i_rp /* i_ftype==IFREG || i_ftype==IFBLK */
#define i_sptr i_un.i_sp /* i_ftype==IFCHR || i_ftype==IFIFO */
#define i_sem i_un.isem /* i_ftype==IFNAM && i_namtype==IFSEM */
#define i_sd i_un.isd /* i_ftype==IFNAM && i_namtype==IFSHD */

struct fstypsw *i_fstypp; /* ptr to file system switch FSPTR */
long *i_filocks; /* pointer to filock (structure) list */
unsigned long i_mappages; /* number of pages currently cached */
unsigned long i_vcode; /* read-ahead block save (NFS) */
short i_wcnt; /* write open count or ITEXT count */
struct lockb i_cilock; /* tas to synchronize i_flag changes */
ushort i_rdlocks; /* count of non-exclusive lockers */
} inode_t;

ËùÒÔ,·ÃÎÊÒ»¸öÎļþ²»ÄܸıäinodeÐÅÏ¢.
ʹÓÃchown, chgrp, chmodÃüÁî¿ÉÒԺܺõıȽÏmtimeºÍctime
chown¸Ä±äÒ»¸öÎļþµÄÊôÖ÷,ÓÃctime¿ÉÒÔÕÒµ½,ÓÃmtime±ãÕÒ²»µ½.
ÊÔÊÔ¿´.

¶àл°ßÖñ! ÎÒÊÇÔÚ Solaris ÉÏÃæÊÔµÄ.ÎÒÊÇ¶Ô -ctime ²»Ã÷°×.
ÊԵĽá¹ûÈçÏÂ:
ÐÞ¸ÄÎļþ,-mtime ¸ÄÁË, -ctime Ò²»á¸Ä.
·ÃÎÊÎļþ,-atime ¸ÄÁË, -ctime û±ä.
chown, chgrp, chmod,mv, ¶¼»áʹ -ctime ¸Ä±ä,µ«²»Ó°Ïì -atime ºÍ -mtime.
touch ¿ÉÒÔ¸Ä -mtime and/or -atime,µ« touch -a Ö»¸Ä·ÃÎÊʱ¼äʱ,-ctimeÒ²¸ÄÁË.
touch -m ¸ÄÐÞ¸Äʱ¼äʱ,-ctimeµ±È»Ò²¸ÄÁË.
ºÃÏó»¹ÓбðµÄºÜ¶à¶«Î÷¿ÉÒÔÁî -ctime ¸Ä±ä, ¸ã²»Çå³þ.
ÓÐʲô·½·¨¿ÉÒÔÏÔʾ -mtime,atime,ctime Âð?
¿ÉÒÔÓà -ctime À´ÊµÏÖ¶ÔĿ¼µÄÔöÁ¿Îļþ½øÐб¸·Ý»ò transfer Âð ?
¶àл!

ûÓÐʲô¹¤¾ßÏÔʾ,(¿ÉÄÜÊǰ³²»ÖªµÀ)
°ÑÏÂÃæ³ÌÐòÀïµÄst_mtime»»³Ést_ctime,»òst_atime±ã¿ÉÒԵõ½ÄãÒªµÄÁË.
#include
int
main (int argc, char **argv)
{
struct stat buf;
char date[80];
char fname[80];
printf("Enter filename (with full path) to check mtime : ");
scanf("%s",fname);
stat(fname, &buf);
printf ("mtime (in sec) of %s = %ld\n", fname, buf.st_mtime);
strcpy(date, ctime((time_t *)&(buf.st_mtime)));
printf ("mtime (in date) of %s = %s\n", fname, date);
}

ÖÁÓÚÎļþ±¸·Ý,ÓÐʲô²»¿ÉÒÔµÄô?

mtime ls -l ×î½üÐÞ¸ÄÎļþÄÚÈݵÄʱ¼ä
atime ls -lu ×î½ü·ÃÎÊÎļþµÄʱ¼ä
ctime ls -li ×î½üÎļþÓÐËù¸Ä±äµÄ״̬ ,ÈçÎļþÐÞ¸Ä,ÊôÐÔ\ÊôÖ÷ ¸Ä±ä ,½Úµã ,Á´½Ó±ä»¯µÈ ,Ó¦¸ÃÊDz»¾ÐÄàÖ»ÊÇʱ¼äǰºóµÄ¸Ä±ä

°³¿´ÁËlsµÄ°ïÖú,ÒÔΪֻÊǰ´ctime»òatimeÅÅÐò,ÏÔʾµÄʱ¼ä»¹ÊÇmtime.

×Ðϸ±È½ÏÁËÒ»ÏÂ,ayhan˵µÄÊǶԵÄ.ллayhan.

¶àл ahyan Ìáʾ ! ÎÒÔÚ Solaris ÉÏÊÔ¹ýÈçÏÂ:
mtime ÓÃ ls -l ¿´µ½
atime ÓÃ ls -lu ¿´µ½
ctime ÓÃ ls -lc ¿´µ½. (ls -li Ö»ÓÐ inode number)
ÕªÊéÈçÏÂ:
-c Uses time of last modification of the i-node (file
created, mode changed, and so forth) for sorting (-t)
or printing (-l or -n).
-u Uses time of last access instead of last modification
for sorting (with the -t option) or printing (with the
-l option).
-i For each file, prints the i-node number in the first
column of the report.

À´Ô´£ºLinuxÉçÇø
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ