rm コマンドでゴミ箱へ

うっかりミスで重要なドキュメントを削除。って、ことが頭にあるのでrmコマンドを使用する際には慎重に行っています。よくmvコマンドとrmコマンドを打ち間違うことがあるので、オプション-iを付けて対処していました。rm コマンドで~/.Trashへ移動するのであれば安心ですね。

function rm () {
  local path
  for path in "$@"; do
    # ignore any arguments
    if [[ "$path" = -* ]]; then :
    else
      local dst=${path##*/}
      # append the time if necessary
      while [ -e ~/.Trash/"$dst" ]; do
        dst="$dst "$(date +%H-%M-%S)
      done
      mv "$path" ~/.Trash/"$dst"
    fi
  done
}

(Via macosxhints.com – A shell function to make ‘rm’ move files to the trash)

このスクリプトをファイルにして実行権限を持たせるか、~/.bash_profileに書き足すかはお好みで。

This entry was posted in UNIX/Linux and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">