【发布时间】:2017-07-22 08:53:21
【问题描述】:
我一直在使用以下 shell bin/bash 脚本作为应用程序,我可以在其中放置一个文件夹,它会更新文件夹的修改日期以匹配该文件夹中最近修改的文件。
for f in each "$@"
do
echo "$f"
done
$HOME/setMod "$@"
这会获取文件夹名称,然后将其传递给我的主文件夹中的这个 setMod 脚本。
#!/bin/bash
# Check that exactly one parameter has been specified - the directory
if [ $# -eq 1 ]; then
# Go to that directory or give up and die
cd "$1" || exit 1
# Get name of newest file
newest=$(stat -f "%m:%N" * | sort -rn | head -1 | cut -f2 -d:)
# Set modification date of folder to match
touch -r "$newest" .
fi
但是,如果我一次将多个文件夹放在上面,它将无法正常工作,而且我不知道如何让它同时与多个文件夹一起工作。
此外,我从 Apple 支持了解到,我的许多文件夹不断更新 mod 日期的原因是由于一些与 Time Machine 相关的过程,尽管事实上我已经多年没有碰过其中的一些。如果有人知道防止这种情况发生的方法,或者以某种方式自动定期更新文件夹的修改日期以匹配其中最近修改文件的日期/时间,那我就不必运行此步骤非常定期地手动操作。
【问题讨论】:
标签: bash shell applescript