比较文件的日期庆典 [英] compare file's date bash

查看:70
本文介绍了比较文件的日期庆典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个微小的下拉框状的bash脚本,我怎么能比较2文件的日期和替换旧(S)用新的未使用的的rsync
有没有简单的方法来处理这​​个?
可以在 SHA1 帮助我知道新的?

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 for knowing the newer?

推荐答案

您可以用测试,使用 -nt (比新)和 -ot (年龄大于)运算符:

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

这篇关于比较文件的日期庆典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆