find検索
8080 ワード
Linux find
•find path -option [ -print ] [ -exec -ok command ] {} \;
#-print
#-exec command {} \; —– command ,{} \;
#-ok -exec ,
====================================================
-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 ,
-prune #
=====================================================
$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"