Skip to main content
added 202 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

POSIXLY:

f1=/path/to/file_1 f2=/path/to/file_2 if [ -n "$(find -L "$f1" -prune -newer "$f2" -exec echo . \;)" ]; then printf '%s is newer than %s\n' "$f1" "$f2" fi 

Using absolute path to files prevent a false positive with filename contains newlines only.

In case of using relative path, then change find command to:

find -L "$f1" -prune -newer "$f2" -exec echo . \; 

POSIXLY:

f1=/path/to/file_1 f2=/path/to/file_2 if [ -n "$(find -L "$f1" -prune -newer "$f2" -exec echo . \;)" ]; then printf '%s is newer than %s\n' "$f1" "$f2" fi 

POSIXLY:

f1=/path/to/file_1 f2=/path/to/file_2 if [ -n "$(find -L "$f1" -prune -newer "$f2")" ]; then printf '%s is newer than %s\n' "$f1" "$f2" fi 

Using absolute path to files prevent a false positive with filename contains newlines only.

In case of using relative path, then change find command to:

find -L "$f1" -prune -newer "$f2" -exec echo . \; 
edited body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

POSIXLY:

f1=/path/to/file_1 f2=/path/to/file_2 if [ -n "$(find "$f1" -L "$f1" -prune -newer "$f2" -exec echo . \;)" ]; then printf '%s is newer than %s\n' "$f1" "$f2" fi 

POSIXLY:

f1=/path/to/file_1 f2=/path/to/file_2 if [ -n "$(find "$f1" -L -prune -newer "$f2" -exec echo . \;)" ]; then printf '%s is newer than %s\n' "$f1" "$f2" fi 

POSIXLY:

f1=/path/to/file_1 f2=/path/to/file_2 if [ -n "$(find -L "$f1" -prune -newer "$f2" -exec echo . \;)" ]; then printf '%s is newer than %s\n' "$f1" "$f2" fi 
added 3 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

POSIXLY:

f1=/path/to/file_1 f2=/path/to/file_2 if [ -n "$(find "$f1" -L -prune -newer "$f2" -exec echo . \;)" ]; then printf '%s is newer than %s\n' "$f1" "$f2" fi 

POSIXLY:

f1=/path/to/file_1 f2=/path/to/file_2 if [ -n "$(find "$f1" -prune -newer "$f2" -exec echo . \;)" ]; then printf '%s is newer than %s\n' "$f1" "$f2" fi 

POSIXLY:

f1=/path/to/file_1 f2=/path/to/file_2 if [ -n "$(find "$f1" -L -prune -newer "$f2" -exec echo . \;)" ]; then printf '%s is newer than %s\n' "$f1" "$f2" fi 
If $f1 is a directory, don't recurse into it
Source Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k
Loading
added 16 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420
Loading
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420
Loading