![](/img/trans.png)
[英]Following symlinks with find to return the file the symlink is pointing to, not the symlink itself
[英]bash: After testing mtime by following a symlink, I need to delete the symlink itself and not the target 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
現在,第一個find命令將刪除目標,而不是符號鏈接。
簡單使用
-exec rm {} +
rm
將刪除鏈接本身,而不是目標。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.