![](/img/trans.png)
[英]Linux bash script to find and delete oldest file with special characters and whitespaces in a directory tree if condtion is met
[英]Delete oldest file for each directory in a tree
我有一個如下所示的目錄樹:
Games
-- Game1
-- file1
-- file2
-- file3
-- Game2
-- file1
-- file2
-- GameN
-- filen
我想刪除每個游戲子目錄中最舊的文件。
嘗試搜索已發布的各種問題,但沒有找到解決方案。
謝謝
如果文件不包含特殊字符,如\n
(帶空格的文件沒有問題):
for dir in Games/Game*/; do
(
cd "$dir"
echo rm "$(\ls -tr | sed q)"
)
done
這是我解析ls
的唯一一種情況
如果您的嘗試令人滿意,請刪除echo
命令。
ls -tr
按修改日期倒序排列文件。sed q
走第一線
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.