linux – -maxdepth选项后不能选择AND find:path必须先于表达式

希望有人可以帮助这个:

尝试使用此命令删除/ tmp上的会话文件:

find /tmp -name 'sess_*' -user Username -maxdepth 1 $CMD {} \;

但是我收到以下错误:

find: warning: you have specified the -maxdepth option after a
non-option argument -name,but options are not positional (-maxdepth
affects tests specified before it as well as those specified after
it). Please specify options before other arguments.

06001

我通过网络寻找解决方案,但找不到任何解决方案.我已经删除其他tmp文件与其他命令,并怀疑是否影响一些卷或套接字.

先谢谢你

解决方法

find有三种类型的选项:用于匹配文件的选项(例如-name,-user),指定在匹配文件(-print,-exec)上执行的操作的选项以及控制整个行为的选项命令(例如-maxdepth,-xdev).第三种必须放在另外两种之前.所以应该是:
find /tmp -maxdepth 1 -name 'sess_*' -user Username -exec $CMD {} \;

相关文章

linux常用进程通信方式包括管道(pipe)、有名管道(FIFO)、...
Linux性能观测工具按类别可分为系统级别和进程级别,系统级别...
本文详细介绍了curl命令基础和高级用法,包括跳过https的证书...
本文包含作者工作中常用到的一些命令,用于诊断网络、磁盘占满...
linux的平均负载表示运行态和就绪态及不可中断状态(正在io)的...
CPU上下文频繁切换会导致系统性能下降,切换分为进程切换、线...