moving files to the (KDE) trash can from the command line

7 October, 2005 - 11:52
Categories:

When you want get rid of some files, but fully deleting them is bit drastic, a trash can is an handy option. In a graphical environment the tools are there to do it (drag and drop, right mouse button on a file, etc.), but on the command line it is not something very handy to do. In the old days there was a directory ~/Desktop/Trash that acted as the trash can. But nowadays, KDE and Gnome implement the freedesktop.org trash specification, which is more advanced than a simple directory with files. This makes it less straightforward to access the trash can from the command line.

When KDE is installed, the KDE file manager can be used from the commandline to do it:

$> kfmclient move foobar.txt trash:/

will move foobar.txt to the trash can.

To make it a bit more userfriendly, you can put the following script in a directory in your $PATH, call it something like totrash and make it executable:

#!/bin/bash
# Move files to trash:/
kfmclient move "$@" trash:/

On the commandline you only need then

$> totrash foobar.txt pleezeew.hu

and you're done.

Based on http://www.kde-forum.org/post/41787/lastpost.html#post41787

25 June, 2011 - 18:12

correction

Anonymous (not verified)

As kfmclient does not support move, change it to kioclient:
#!/bin/bash
# Move files to trash:/
kioclient move "$@" trash:/

25 June, 2011 - 18:08

correction

Anonymous (not verified)

As kfmclient does not support move, chango it to kioclient:
#!/bin/bash
# Move files to trash:/
kioclient move "$@" trash:/

22 May, 2011 - 09:44

Out of date

private_lock (not verified)

But since this is listed in the top search results:

KFMClient doesn't support the move command any longer. Instead search for 'trash-cli' in your distributions repositories.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed
  • Lines and paragraphs break automatically.

More information about formatting options