Skip to content

Instantly share code, notes, and snippets.

@nacardin
Created August 10, 2021 00:04
Show Gist options
  • Save nacardin/f9c6e2b5c745eb2d5fe030a60e64dfb2 to your computer and use it in GitHub Desktop.
Save nacardin/f9c6e2b5c745eb2d5fe030a60e64dfb2 to your computer and use it in GitHub Desktop.
Is dir newer
#!/bin/bash -e
src_dir=$(readlink -f $1)
dst_dir=$(readlink -f $2)
src_timestamp=$(find $src_dir -type f -printf "%T+\n" | sort | tail -1)
dst_timestamp=$(find $dst_dir -type f -printf "%T+\n" | sort | tail -1)
if [ -z $dst_timestamp ]; then
echo "$dst_dir does not exist"
elif [[ $src_timestamp > $dst_timestamp ]]; then
echo "$src_dir is newer than $dst_dir"
else
echo "$src_dir is not newer than $dst_dir"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment