はじめに
コマンド上では、rmでファイル削除を行うが、その場合にはファイルの復元操作などは出来ない。
GUIでの操作の削除はゴミ箱を経由するが、trashコマンドでCLI上でもGUIと同じようにゴミ箱を経由してくれるようになる。
今回は、trashコマンドをインストールして使ってみる。
https://formulae.brew.sh/formula/trash
環境
Mac OS Sonoma 14.4
Homebrew 4.2.12trashのインストール
brew install trashbrew install trash
==> Downloading https://formulae.brew.sh/api/formula.jws.json
==> Downloading https://formulae.brew.sh/api/cask.jws.json
==> Downloading https://ghcr.io/v2/homebrew/core/trash/manifests/0.9.2-1
################################################################################################################################################# 100.0%
==> Fetching trash
==> Downloading https://ghcr.io/v2/homebrew/core/trash/blobs/sha256:c26e06202022f708790f22f4477b65e3337d611c42e9a814ada1526bda03d923
################################################################################################################################################# 100.0%
==> Pouring trash--0.9.2.sonoma.bottle.1.tar.gz
🍺 /usr/local/Cellar/trash/0.9.2: 5 files, 61.0KB
==> Running `brew cleanup trash`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).trashを使う
適当なファイルを作成する
echo "Hello,World" >> hello.txt~$ echo "Hello,World" >> hello.txt
~$ cat hello.txt
Hello,Worldtrashコマンドでゴミ箱へ移動する
trash hello.txtゴミ箱を見てみる。
trash -ltrash -l
/Users/anonymous/.Trash/hello.txt存在してた。
復元をしてみる
復元のオプションはないようなので、ゴミ箱から移動させる。
mv /Users/anonymous/.Trash/hello.txt hello.txtゴミ箱を空にする
trash -etrash -e
There are currently 15 items in the trash.
Are you sure you want to permanently delete these items?
(y = permanently empty the trash, l = list items in trash, n = don't empty)
[y/l/N]: y削除できたかを確認する。
trash -l何も表示されなければOK
おわりに
CLI上では、rmを使うが後で復元するかも…?みたいな作業の際に今回のコマンドは使えるのかもしれない。
バックアップを取れって話ではあるのだが…。