我正在处理一个bash脚本,该脚本旨在删除具有特定扩展名的文件,并且当我检查这些文件是否仍然存在时,我不希望它返回"没有此文件或目录"的输出。相反,我希望它返回自定义消息,例如:"您已经删除了这些文件"。
以下是该脚本:
#!/usr/bin/env bash
read -p "are you sure you want to delete the files? Y/N " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm *.torrent
rm *.zip
rm *.deb
echo "all those files have been deleted............."
fi
find
命令吗? - Mad Physicistfind -name '*.torrent' -o -name '*.zip' -o -name '*.deb' -delete
这样的命令可以完全避免你的问题,但可能并不是你想要的,因为它不会报告一开始就没有给定类型的文件。 - Mad Physicist