compare file's date bash

前端 未结 4 1251
执笔经年
执笔经年 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条回答
  • 2021-01-03 18:02

    Here is a POSIX solution:

    find -name file2 -newer file1
    
    0 讨论(0)
  • 2021-01-03 18:07

    Or even shorter and nicer, look at man stat:

    stat -c %y file
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-01-03 18:18

    how about

     stat file|awk -F': ' '/Modify: /{print $2}'
    
    0 讨论(0)
提交回复
热议问题