linux shell中“find”命令的“-newer $ file”选项如何工作?

时间:2014-07-24 07:38:27

标签: linux shell command

我有以下linux命令。

find ${MOUNT_POINT} -type f -name "VM*" -newer $SENTFILE -print0 | xargs -0 -i cp {} ${TMP_DIR}

我很难理解选项-newer $SENTFILE。有人可以解释这个选项吗?

2 个答案:

答案 0 :(得分:2)

来自man find

-newer file
    File  was  modified  more recently than file.  If file is a sym‐
    bolic link and the -H option or the -L option is in effect,  the
    modification time of the file it points to is always used.

答案 1 :(得分:0)

如果使用空格扩展$SENTFILE,则可能有不好的事情(将几个参数传递给find)。我建议引用它像

 find ${MOUNT_POINT} -type f -name "VM*" -newer "$SENTFILE" -print0 \ 

否则,-newer就像pfnuesel answered一样。我想find正在使用stat(2)(然后比较st_mtime的{​​{1}}字段

当然,您的-newer是由调用shell(或某些外部脚本)设置的。它应该包含某个文件的名称。

如果这是某些shell脚本的一部分,请尝试调试该shell脚本,可能是通过

SENTFILE

作为第一行或添加类似

的内容
#!/bin/bash -vx

或者可能(参见logger(1),然后查看系统日志文件,可能在echo SENTFILE is $SENTFILE 2>&1 下)

/var/log/

您对基本shell脚本不够熟悉。请阅读Advanced Bash Scripting Guide或更好的内容。