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

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

问题描述

我正在开发一个类似于 Dropbox 的小型 bash 脚本,如何在不使用 rsync 的情况下比较 2 个文件的日期并用新文件替换旧文件有什么简单的方法来处理这个吗?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 with knowing the newer?

推荐答案

你可以用 test 比较文件修改时间,使用 -nt (newer than) 和 -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

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

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