!/bin/bash
使用方法: ./delete_files.sh /path/to/directory with|without extension
給腳本賦予可執(zhí)行權(quán)限:chmod +x delete_files.sh
DIRECTORY="2"
EXTENSION="$3"
檢查參數(shù)
if [ -z "CONDITION" ] || [ -z "
0 /path/to/directory with|without extension"
echo "'with' : Delete files with the specified extension."
echo "'without' : Delete files without the specified extension."
exit 1
fi
根據(jù)條件刪除文件
if [ "DIRECTORY" -type f -name "*.
EXTENSION files in
CONDITION" == "without" ]; then
# 刪除非指定后綴的文件
find "EXTENSION" -exec rm -f {} +
echo "Deleted all files NOT with *.DIRECTORY"
else
echo "Invalid condition: $CONDITION. Use 'with' or 'without'."
exit 1
fi