Kyaw Zin Htoo Naing
Kyaw Zin Htoo Naing

Reputation: 237

How does the "-newer $file" option of "find" command in linux shell work?

I have following linux command.

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

I am having difficulty understanding the option -newer $SENTFILE. Could anybody explain this option?

Upvotes: 4

Views: 3879

Answers (2)

If $SENTFILE is expanded with spaces, you might have bad things (several arguments passed to find). I would recommend quoting it like

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

Otherwise, -newer works like pfnuesel answered. I guess that find is using stat(2) (then comparing the st_mtime fields for -newer)

Of course, your SENTFILE is set by the invoking shell (or some outer script). It should contain the name of some file.

If this is part of some shell script, try debugging that shell script, perhaps by having

#!/bin/bash -vx

as its first line or add something like

echo SENTFILE is $SENTFILE 2>&1

or maybe (see logger(1), then look in your system log files, probably under /var/log/)

logger -s SENTFILE is $SENTFILE 

You are not familiar enough with basic shell scripting. So read Advanced Bash Scripting Guide or something better.

Upvotes: 1

pfnuesel
pfnuesel

Reputation: 15330

From 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.

Upvotes: 4

Related Questions