博客园  :: 首页  :: 管理

每天一个Linux命令-find.

Posted on 2023-04-20 15:43  520_1351  阅读(80)  评论(0编辑  收藏  举报

find命令主要用于在linux查找出符号条件的文件(也可以包含目录),先在最前面记录一些重点

1、find 命令后面的多个条件时,默认是 与/&/和 的逻辑

2、只要不指定层数进行find,默认是会一直递归到最后一层的

3、常用的多条件可以使用 -a 连接表示 并且, -o 表示 或者 

4、单个条件取反,可以使用 !符号 ,用在条件的前面

 

这里笔者列出自己在工作中用到过的一些例子

1、从当前目录开始,查找owner是nginx的文件:find ./ -type f -user nginx

对于owner,我们可以通过 -user xxx 指定用户名,其实xxx也可以写成 uid的

对于group,我们可以通过 -group xxx 指定用户组名,其实xxx也可以写成gid的

注意:如果用户或者用户组被删除了,那么之前他们的文件上的属性,就不会显示成名称了,而是只会显示uid 和 gid了

这样我们在查找时,就只能通过-uid xxx 和 -gid xxx 的方式了,这里的xxx只能写数字,不能写名称

2、关于find命令的单条件逻辑符与多条件的逻辑处理,说明如下

   OPERATORS
       Listed in order of decreasing precedence:

       ( expr )
              Force precedence.  Since parentheses are special to the shell, you will normally need to quote them.  Many of the examples in  this  manual
              page use backslashes for this purpose: `\(...\)' instead of `(...)'.

       ! expr True if expr is false.  This character will also usually need protection from interpretation by the shell.

       -not expr
              Same as ! expr, but not POSIX compliant.

       expr1 expr2
              Two expressions in a row are taken to be joined with an implied "and"; expr2 is not evaluated if expr1 is false.

       expr1 -a expr2
              Same as expr1 expr2.

       expr1 -and expr2
              Same as expr1 expr2, but not POSIX compliant.

       expr1 -o expr2
              Or; expr2 is not evaluated if expr1 is true.

       expr1 -or expr2
              Same as expr1 -o expr2, but not POSIX compliant.

       expr1 , expr2
              List;  both expr1 and expr2 are always evaluated.  The value of expr1 is discarded; the value of the list is the value of expr2.  The comma
              operator can be useful for searching for several different types of thing, but traversing the filesystem hierarchy only once.  The -fprintf
              action can be used to list the various matched items into several different output files.

 

 

 

 

 

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/17337128.html