compare file's date bash

前端 未结 4 1275
执笔经年
执笔经年 2021-01-03 17:36

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 t

4条回答
  •  梦毁少年i
    2021-01-03 18:15

    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
    

提交回复
热议问题