Control Your Trash

Recently I discovered a set of command line tools that allow you to interact with the trash can: trash-cli. Normally only GUI file managers like Nautilus will use the trash can, if you delete files on the command line using rm or rmdir the trash can is bypassed and files are deleted immediately.

With trash-cli you get several commands:

  • trash-put - to remove files by sending them to the trash can
  • trash-list - to list the content of the trash can
  • trash-restore - to restore files
  • trash-empty - to purge old files

In Ubuntu Intrepid and Jaunty there is an older package of trash-cli, but the authors are not recommending it (too bad the latest version was not packaged for Jaunty). The current installation instructions are really easy:
$ sudo easy_install trash-cli

An interesting application is to automatically purge older items from your trash can. The following command will purge files older than a week:
$ trash-empty 7

If you add this command to your crontab then you don't have to worry about emptying your trash anymore. The following crontab line will run the trash-empty command every hour:
13 * * * * /usr/local/bin/trash-empty 7

While the above is really easy to install and works nice, there are a few things that could be improved.

It would be nice if trash-empty listed the files it purged so they can be appended to a log file. You can achieve this by listing the trash before and after emptying it, and diffing the two list, but that is a bit too much.

Currently the only way to empty the trash is by specifying a number of days. I'm sure some people would prefer to set a maximum size for the trash can.

Technorati Tags:Technorati Tags:

No comments yet

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options