zsh-shell-init/alias.d/opt/rm_repate.sh
2023-09-13 17:10:07 +08:00

23 lines
582 B
Bash
Executable File

#!/bin/bash
dir="$HOME/Documents/SyncDir/Profile"
name=$(scutil --get ComputerName)
dst="$dir/$name/"
if [ "$#" -eq 0 ]; then
dir="$dst"
else
dir="$1"
fi
echo "scan in $dir"
for file in "$dir"/*; do # 遍历目录下的所有文件和子目录
if [ -f "$file" ] && [[ "$file" == *" "*[0-9]* ]]; then # 如果是普通文件且以数字结尾
rm "$file" # 删除文件
echo "Deleted $file" # 输出删除文件的信息
elif [[ -d "$file" ]]; then # 如果是子目录
"$0" "$file" # 递归调用脚本处理子目录
fi
done