如何从终端中清空垃圾?


Answers:


23

另一个解决方案是创建包含以下代码的AppleScript

tell application "Finder"
    empty the trash
end tell

emptytrash例如将其保存并通过执行open emptytrash.app

甚至更好(如克里斯的建议)-执行:

osascript -e 'tell app "Finder" to empty'

由于垃圾是Finder的东西,从长远来看,这应该更加兼容。


6
直接从命令行:(osascript -e 'tell app "Finder" to empty'尽管您可能希望放入shell脚本以避免每次都必须正确获取语法)。
克里斯·约翰森

11

废纸actually实际上是用户名为的文件夹中的隐藏文件夹 .Trash

如果删除其中的内容,则清空垃圾箱。您可以使用

rm -rf ~/.Trash/*

请小心,以免删除其他内容;)


8
但这不会删除已挂载媒体/网络卷上的.Trash。
mspasov 2011年

@mspasov,在许多情况下是功能,而不是错误。无论如何,它还会回答:“如何在不卸载外部卷的情况下只清空本地垃圾?” ;)
通配符


3

如果安装了Homebrew,则可以通过键入以下内容轻松安装垃圾桶

brew install trash

然后,要清空垃圾箱,只需从命令行键入以下内容:

trash -e

这是一个很小的软件。

$ trash
usage: trash [-ulesv] <file> [<file> ...]

  Move files/folders to the trash.

  Options to use with <file>:

  -a  Use system API for trashing files instead of asking
      Finder to do it. (Faster, but the 'put back' feature
      in the Finder trash will not work if files are trashed
      using this method.) Finder is still used for trashing
      files you have no access rights for.
  -v  Be verbose (show files as they are trashed, or if
      used with the -l option, show additional information
      about the trash contents)

  Stand-alone options (to use without <file>):

  -u  Check for updates (and optionally auto-update self)
  -l  List items currently in the trash (add the -v option
      to see additional information)
  -e  Empty the trash (asks for confirmation)
  -s  Securely empty the trash (asks for confirmation)

  Options supported by `rm` are silently accepted.

Version 0.8.5
Copyright (c) 2010 Ali Rantakari, http://hasseg.org/trash
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.