我有一个目录,其中包含以数字命名的子目录(例如 1, 2, 3, 32000, 43546 )。我需要删除超过一定数量的所有目录。例如,我需要删除名称数字大于 14234 的所有子目录。这可以通过单个命令行操作来完成吗?
rm -r /directory/subdirectories_over_14234 ( how can I do this? )
在 bash 中,我会写
for dir in *; do [[ -d $dir ]] && (( dir > 14234 )) && echo rm -r $dir; done
自行决定删除echo
。
好吧,您可以执行 bash for 循环指令,以便遍历目录文件名并在提取文件名的目标编号后使用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