我有一个图像目录,我们正在处理,我想删除所有的PNG图像。
我只想删除类似以下内容的文件:
/8k/8095/p_149554/420_1527072930.png
./8k/8095/p_1453/1000_1527072907.png
./8k/8095/p_153/80_1527072907.png
./8k/8095/p_149553/260_1527072907.png
./8k/8095/p_149553/new_origin.png
./8k/8095/p_149553/340_1527072907.png
./8k/8095/p_149553/150_1527072907.png
./8k/8095/p_149553/main.png
./8k/8095/p_149553/420_1527072907.png
./8k/8546/p_162421/340_1530296168.png
./8k/8546/p_162421/150_1530296168.png
./8k/8546/p_162421/main.png
./8k/8546/p_162421/260_1530296168.png
./8k/8546/p_162421/420_1530296168.png
./8k/8546/p_162421/80_1530296168.png
./8k/8546/p_162421/1000_1530296168.png
./8k/8546/p_162419/1000_1530296127.png
./8k/8546/p_162419/260_1530296127.png
./8k/8546/p_162419/80_1530296127.png
./8k/8546/p_62419/340_1530296127.png
./8k/8546/p_62419/150_1530296127.png
./8k/8546/p_62419/main.png
./8k/8546/p_62419/420_1530296127.png我需要删除子文件夹中的所有png文件,这些文件的p_(<100000)或介于1-100000之间
谢谢
发布于 2020-05-25 16:54:24
将正则表达式与find一起使用
find . -type f -regextype egrep -iregex '.*/p_1?[[:digit:]]{0,5}/.*\.png' -print如果输出与要删除的文件匹配,则将-print替换为-delete
在这里查看详细的正则表达式:Regex101
发布于 2020-05-25 16:38:51
请您尝试以下操作:
while IFS= read -r -d "" f; do
dir="${f%/*}" # extract the directory portion
n="${dir/*\/p_/}" # extract the number after "p_"
if (( n > 1 && n < 100000 )); then # if the number is between 1 and 100,000
echo "$f"
# rm -- "$f" # uncomment if the result is ok
fi
done < <(find . -type f -name "*.png" -print0) # feed the result of "find" to the "while" loop如果您对between的定义是inclusive,请将>符号替换为>=,将<替换为<=。
https://stackoverflow.com/questions/61997639
复制相似问题