【发布时间】:2018-10-11 09:42:35
【问题描述】:
我想获取目录中的最后一个(最新)文件。这个脚本适用于我有 bash 文件的目录。
当我将路径更改为另一个路径时,问题在last_modified。脚本看不到file - 我想,但我不知道为什么。有人可以帮忙吗?
下面是我的 test.sh 文件中的代码
#!/bin/bash
file=$(cd '/path_where_is_test.sh_file' && ls -t | head -1)
last_modified=$(stat -c %Y $file)
current=$(date +%s)
if (( ($current - $last_modified) > 86400 )); then
echo 'Mail'
else
echo 'No Mail'
fi;
【问题讨论】:
-
您正在更改目录,但是当调用 Stat 时,您又回到了原始目录。因此,您还必须添加 stat 的路径。
标签: linux bash ubuntu filter last-modified