![](/img/trans.png)
[英]How can I find and delete files based on date in a linux shell script without find?
[英]How can I delete directories based on their numeric name value with a shell script?
我有一個目錄,其中包含以數字命名的子目錄(例如1、2、3、32000、43546)。 我需要刪除超過一定數量的所有目錄。 例如,我需要刪除名稱在數字上大於14234的所有子目錄。可以通過單個命令行操作來完成此操作嗎?
rm -r /directory/subdirectories_over_14234 ( how can I do this? )
好了,您可以執行bash for loop指令,以便遍歷目錄文件名並在提取文件名的目標編號之后使用test命令。
應該是這樣的:
for $file in /your/path
do
#extract number here with any text processing command (ed ?)
if test [$name -leq your_value]
then
rm -R $file
fi
done
用bash,我會寫
for dir in *; do [[ -d $dir ]] && (( dir > 14234 )) && echo rm -r $dir; done
您可以自行決定刪除echo
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.