语法: find [path] [options] [tests] [actions]
[path] 可以传递多个参数, 如: /usr /home …
[options] 常用的选项如下:
-depth: search the content of a directory before looking at the directory itself
-follow: follow symbolic links
-maxdepths N: search at most N levels of the directory
-mount (or -xdev): don’t search directories on other file systems
[tests] 表示查找的时候所用的测试条件, 常用的如下:
-atime N: the file was last accessed N days ago
-mtime N: the file was last modified N days ago
-name pattern: the pattern of the file, must always in quotes
-newer otherfile: the file is newer than the file “otherfile”
-type C: C could be any particular type, “d” is for directory, “f” is normal file
-user username: the file which owned by the username
还可以使用逻辑运算符, 比如: ! 或者-not, -a或者-and, -o或者-or, 前者是短符号, 后者是长符号.
在用的时候要用括号(), 同时括号()需要转义, 例如: (-newer X -or -name “_*” )
[actions] 可以在找到文件后执行操作, 常用的有:
-exec command: this action must end with \;
-ok command: this action must end with \; it will ask for user confirm before execute the command
-print: print out the name of file
-ls: use ls command on file
同样有用的命令是 grep
grep [options] pattern [files]
[options]
-c: rather than print matching lines, print out a count of the number of lines that match
-E: turn on extended expressions
-h: suppress the normal prefixing of each output line with the name of the file it was founded in
-i: ignore case
-l: list the name of files with matching lines, don’t output the actual matched line
-v: invert the matching option to select non-matching lines
正则表达式: