[英]bash: After testing mtime by following a symlink, I need to delete the symlink itself and not the target file
Right now I have a script that creates symlinks to anything newer than 2 weeks in the public folders into another folder. 现在,我有一个脚本,该脚本可将指向公共文件夹中两个星期以上的内容的符号链接创建到另一个文件夹中。 However, I can't find any good way of getting rid of the stale symlinks individually as opposed to wiping everything out.
但是,相对于清除所有内容,我找不到任何摆脱旧符号链接的好方法。 I need to test the symlink target mtime and if it's older than 2 weeks, delete the symlink itself and not the linked file.
我需要测试符号链接目标mtime,如果它的时间超过2周,请删除符号链接本身而不是链接文件。
#!/bin/bash
source="/media/public/"
dest="/pool/new/"
if [[ ! -d $dest ]]; then
exit 1
fi
if [ `hostname` == "punk" ] && [ `uname -o` == "GNU/Linux" ]; then
#rm -f $dest/*
find -L $dest -mtime 14 -type f -exec echo "delete symlink: " {} \;
find -L $source -mtime -14 -type f -exec ln -s -t $dest {} \;
fi
Right now the first find command will delete the target as opposed to the symlink. 现在,第一个find命令将删除目标,而不是符号链接。
Use simply 简单使用
-exec rm {} +
rm
will delete the link itself, not the target. rm
将删除链接本身,而不是目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.