从终端把文件移到废纸篓(可恢复删除)
终端删除文件也有后悔药:让 Finder 把文件放进废纸篓而不是直接抹掉。
运行 osascript 的 Finder delete 一行命令并给出完整路径,文件就会进入废纸篓。
01命令
命令
$ osascript -e 'tell application "Finder" to delete POSIX file "/Users/you/Desktop/old-report.pdf"'02作用说明
rm 删除是永久的,而 Finder 的 delete 会把文件放进废纸篓,随时可以放回去,写清理脚本时更安全。路径必须是绝对路径,可在脚本里定义函数 trash() { osascript -e "tell app \"Finder\" to delete POSIX file \"$1\"" ; },之后 trash 文件名 即可。想真正释放空间,再清空废纸篓。
03风险
!注意: 文件在清空废纸篓前仍占磁盘空间,这种方式删大文件不会立刻释放容量。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- Delete files and folders on Mac依据: Apple documents that deleted files go to the Trash where they can be put back.
- osascript – Execute AppleScript and OSA scripts依据: osascript -e runs an AppleScript one-liner; Finder's delete verb moves items to the Trash instead of erasing them.
最后验证: 2026-09-18 · 分类: 文件与文件夹