find
syntax:
find path pattern findname
description:
pattern is regular expression or options
find -name
example: find / -name '*alpha*'
find -type option file
the frquence option:
f regular file(普通文件)
d directory(目录)
b block device(块设备)
c character device(字符设备)
l symbolic link(符号链接)
p named pipe(命名管道)
find: -mtime, -atime, -ctime, -mmin, -cmin, -amin
-mtime n file was the last modified n days ago, greater than or less than or exactly n days
-mmin n file was the last modified n minutes ago. greater than or less than or exactly n minutes.
-atime n file was the last accessed n days ago,greater than or less than or exactly n days
-amin n file was the last accessed n minutes ago,greater than or less than or exactly n minutes
-ctime n file was the last changed n days ago, greater than or less than or exactly n days
-cmin n file was the lasy changed n minutes, greater than or less than or exactly n minutes
+n for greater than n
- for less than n
n for exactly n
example:
find the files no changed less than 5 days rently:(查找在最近5天内没有被改变的文件)
$find /usr -ctime -5
find -size
+n greater than n disk blocks
-n less than n disk blocks
n exactly n disk blocks
example:
find the all files which greater than 200 blocks
find /usr -size +200
find union option
multiple option were specified, output the files which match all options
example:
find filename is alpha, the size is greater than 500 blocks and the last modified time less than 3 days:
find /usr -name alpha -size +500 -mtime -3
-o indicate or
example:
find files which size are greater 50 blocks or the last accessed time was less than 3 days.
find /usr \( -size +50 -o -atime -3 \)
find deny option
You can use the ! to find the not match files.
example:
find /usr ! \( -type b -o type d \)
-exec command ;
Execute command; true if 0 status is returned. All following
arguments to find are taken to be arguments to the command until
an argument consisting of `;' is encountered. The string `{}'
is replaced by the current file name being processed everywhere
it occurs in the arguments to the command, not just in arguments
where it is alone, as in some versions of find. Both of these
constructions might need to be escaped (with a `\') or quoted to
protect them from expansion by the shell. The command is exe-
cuted in the starting directory.
example: find / -name core -exec rm -r {} \; (utility)
the \ indicate escape. it must include, otherwise it will output false.
对于一个系统管理员,这是一个常见的周期性的用法,如果一个进程异常退出,就会在当前目录中产生一个名为core的调试文件. 随后这些并不是很大的文件聚集在一起占用了大量的无用的磁盘空间.这个find命令可以通过查找并删除的方法来恢复磁盘空间.
the other options:
-gid groupID
-group 'roupname or group ID'
-uid uerID
-user 'username or user ID'
-lname 'symbolic name
|