I'm working on a tiny dropbox-like bash script, how can I compare the dates of 2 files and replace the old one(s) with the new one without using rsync is there any simple way to process this? can the SHA1 help me with knowing the newer?
You can compare file modification times with test
, using -nt
(newer than) and -ot
(older than) operators:
if [ "$file1" -ot "$file2" ]; then
cp -f "$file2" "$file1"
fi