#!/bin/bash

# 安全删除脚本 safe-rm

# 检查是否有文件或目录作为参数
if [ "$#" -eq 0 ]; then
    echo "Usage: safe-rm [file/directory...]"
    exit 1
fi

# 提示用户确认
echo "Are you sure you want to delete the following files/directories? (yes i do to confirm)"
for file in "$@"; do
    echo "$file"
done

# 等待用户输入
read confirmation

# 验证用户输入
if [ "$confirmation" = "yes i do" ]; then
    # 调用原始 rm 命令执行删除
    /bin/rm "$@"
else
    echo "Deletion aborted."
fi
设置别名:
在用户的.bashrc或.zshrc文件中添加以下行,以设置rm的别名:

bash
alias rm='safe-rm'