write a file: ~/rm.sh.
#!/bin/bash # # move files to trash bin, rather than deleting them # (and doesn't overwrite previously deleted files of the same name). OS=$(uname -s) case $OS in 'Darwin') trash_dir="$HOME/.Trash" ;; 'Linux') trash_dir="$HOME/.local/share/Trash/files" ;; esac if [ ! -d $trash_dir ]; then echo "Creating Trash directory $trash_dir." mkdir $trash_dir fi # change delimiter $IFS to newline IFS=' ' for file in $@; do base=$(basename "$file") newfile=$base while [ -e $trash_dir/$newfile ]; do random_suffix=$RANDOM newfile=${base}.${random_suffix} done mv "$file" "$trash_dir/$newfile" done unset IFS
modify ~/.bashrc.
alias remove='/bin/rm' alias rm='~/rm.sh'
Hide Comments