小编new*_*own的帖子

如何比较bash中的文件时间戳?

如何比较两个文件的时间戳?

我试过这个,但它不起作用:

file1time=`stat -c %Y fil1.txt`
file2time=`stat -c %Y file2.txt`
if[$file1time -gt $file2time];
then
 doSomething
fi
Run Code Online (Sandbox Code Playgroud)

我按顺序打印了两个时间戳,它给了我

1273143480
1254144394
./script.sh: line 13: [1273143480: command not found
Run Code Online (Sandbox Code Playgroud)

所以基本上如果比较不起作用,我想。或者如果有任何其他比我正在做的更好的方式,请告诉我。我需要改变什么?

linux bash comparison timestamp

20
推荐指数
2
解决办法
4万
查看次数

标签 统计

bash ×1

comparison ×1

linux ×1

timestamp ×1