brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: the trash command in the macOS terminal moves files to the Trash, not into oblivion

Terminal
~/tips/tip-terminal-trash-command-macos

trash old-notes.txt build/

Deletes from the command line in a way you can still undo from Finder.

rm has no undo. Since macOS 15 there is a built-in command that sends files to the Trash, just like Command-Delete in Finder.

It takes files and folders, several at once:

trash old-notes.txt build/
trash -v *.log

With -v it prints where each item went, normally your ~/.Trash. From there, Put Back in Finder restores the file to its old folder, same as for anything you deleted by hand. I’d use it for cleanups where you’re only fairly sure.

In a script, -s makes it stop with an error when a move fails, so the script doesn’t continue as if everything was removed.

It lives in /usr/bin/trash and first appeared in macOS 15. On older versions the name may point to a Homebrew package with different options, so check with which trash. Also, the Trash still takes disk space, so for freeing space this alone does nothing until you empty it.

Further reading: trash man page (macOS)

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link