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 use date +%s -d your_date to get the number of seconds since a fixed instance (1970-01-01, 00:00 UTC) called "epoch". Once you get that it's really easy to do almost anything with dates.
If so, you can lexicographically compare your timestamp with the output of date -u -d '-10 minutes' +%Y%m%d%H%M%S (the -u assumes that your database timestamp is in UTC, which I'd advise).
From man bash : -s If the -s option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With