0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Homebrewのrmtrashが無い…?

Last updated at Posted at 2021-10-03

2021/10/03投稿

※最新版はharoot.netに移動しました。

結論

rmtrashが無い原因は見つかりませんでしたがtrashを代わりに入れたら機能しました。

環境

macOS Big Sur 11.3

動機

ターミナルのrmコマンドで誤って必要なファイルを消してしまったため、消さずにゴミ箱に移動するだけに変えようと思った。
調べるとHomebrew経由でrmtrashというゴミ箱に移動するだけのコマンドがあるらしいので入れてみる。

brew install rmtrash

実行結果 :

Updating Homebrew...
(略)

Warning: No available formula or cask with the name "rmtrash". Did you mean trash?
==> Searching for similarly named formulae...
This similarly named formula was found:
trash
To install it, run:
  brew install trash
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

rmtrashなんてパッケージはない。trashの間違いでは?と言われた。
念の為Homebrewサイトのパッケージ一覧から探してみたが確かにそんなパッケージは無かった…
trashに変わったんですかね?(わかる人いたら教えてください)

trashを入れてみる

言われた通りtrashを入れてみます。(サイトのパッケージ一覧見たらmacos-trashというのもありました。違いはわかりませんが。)

brew install trash

実行結果 :

==> Downloading https://ghcr.io/v2/homebrew/core/trash/manifests/0.9.2-1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/trash/blobs/sha256:403ba52ce97d38535e1d127ca227afd4ea2d0e0c8b
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:403ba52ce97d38535e1d127ca
######################################################################## 100.0%
==> Pouring trash--0.9.2.big_sur.bottle.1.tar.gz
🍺  /usr/local/Cellar/trash/0.9.2: 5 files, 60.8KB
user@usernoMacBook-Pro Desktop %

動作確認

touch A.txt
trash A.txt

実行結果 :
スクリーンショット 2021-10-03 22.42.38.png
ちゃんとゴミ箱に移動してくれました。ちなみにフォルダも同様にtrashのみで消えました(中にファイルがあっても)。

エイリアスを貼る

このままだと間違えてrmコマンド使ってしまいそうなのでrmと打つとtrashが実行されるようにエイリアスを貼ります。
.bash_profileや.zshrcを開き(PCのシェルによって異なります)、

.bash_profileや.zshrcなど
alias rm="trash"

保存してターミナルを再起動したら完了です。

動作確認(エイリアス)

touch A2.txt
rm A2.txt

実行結果 :
スクリーンショット 2021-10-03 23.02.51.png
rmと打ってtrashの動作になっていることが確認できました。

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?