Announcement

Collapse
No announcement yet.

Command line trash bin access

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Command line trash bin access

    Recently I nearly gave myself a heart attack using rm -viR. (I don't normally use the prompting option, but included it here to protect the ignorant.) This isn't the first time I've caught myself being reckless, but I want it to be the last time. So I went Googling and found a couple of possible replacements for the aforementioned merciless command.

    Originally posted by man ktrash
    KTRASH(1) helper program KTRASH(1)

    NAME
    ktrash - Helper program to handle the KDE trash can

    SYNOPSIS
    ktrash [Qt-options] [KDE-options] [options]

    DESCRIPTION
    ktrash is a helper program to handle the KDE trash can.

    Note: to move files to the trash, do not use ktrash, but "kfmclient
    move 'url' trash:/"
    Looks good, seems to work, and it's built in to KDE.

    The second option I found is trash-cli.

    Originally posted by features
    * Command line interface compatible with on of the rm command. You can alias rm with trash.
    * Remembers original path, deletion time and file permissions of each trashed file.
    * Compatible with the KDE trash.
    * Implements the FreeDesktop.org Trash Specification
    * Works with volume other than the home volume (e.g. USB pen or another partition).
    Sounds good, but it's not in the Ubuntu repos so I'd have to manually install. It's written in Python AFAIK.

    Does anyone have experience with either of these? Are there any disadvantages or pitfalls to using either of these in scripts? Is there a better solution?

    Edit: I'm using Kubuntu Hardy Heron 8.04.3. See Rog131's reply for the equivalent command on Jaunty.
    Welcome newbies!
    Verify the ISO
    Kubuntu's documentation

    #2
    Re: Command line trash bin access

    Hi,

    as you probably know the rubbish bin is no more than a normal directory. I therefore see no need for a cli bin 'cos all you need to do is dedicate a "rubbish" directory and _move_ the stuff you don't want anymore into it. You could safely forget about the rm command until you actually want to delete whatever is in that directory.

    And as for being reckless - I know exactly where you are coming from and I try to adhere to the above. So far it has worked, but I'm sure I'll find a way of borking my system despite everything
    Once your problem is solved please mark the topic of the first post as SOLVED so others know and can benefit from your experience! / FAQ

    Comment


      #3
      Re: Command line trash bin access

      Originally posted by toad
      as you probably know the rubbish bin is no more than a normal directory.
      But it is more than a directory. There is also a means for tracking the origin of rubbished files. I think that gives the trash bin a significant advantage over a standard directory. Maybe you could use soft-links or a database, but without some automation that would be a hassle.

      I've sometimes put things into archives instead of deleting them. That's usually what I do with any configuration files. I just put it into a compressed archive with a different name. But that still leaves the archive on my hard disk, and not all my files compress as well as configuration files do.
      Welcome newbies!
      Verify the ISO
      Kubuntu's documentation

      Comment


        #4
        Re: Command line trash bin access

        Originally posted by Telengard
        There is also a means for tracking the origin of rubbished files.
        Good point, never occurred to me as I don't really use it

        Here a list of what Arch throws up when asked for "trash". Perhaps one of them is of use to you - let us know if you find one

        libtrash 3.2-1
        A shared, preloaded library that implements a trash can under Linux
        delsafe 0.6.0-1 (1)
        delsafe is a set of utilities that when you delete a file the file is moved into a trash can via LD_PRELOAD
        libtrash 3.2-1 (9)
        A shared, preloaded library that implements a trash can under Linux
        mutt-trash-nntp 1.5.19-1 (2)
        A small but very powerful text-based mail client. Development version patched with nntp and trash folder support.
        thunar-light 1.0.1-2 (34)
        Xfce file manager compiled for light wm use (no xfce4-panel dep, no wallpaler-plugin, no trash panel plugin)
        trash 0.2-3 (12)
        Command-line utility to move files to a shared trash can
        trash-cli 0.1.10.r55-1 (Out of Date) (3)
        Command line trashcan (recycle bin) interface
        Once your problem is solved please mark the topic of the first post as SOLVED so others know and can benefit from your experience! / FAQ

        Comment


          #5
          Re: Command line trash bin access

          The "kioclient move 'url' trash:/" /1/ seems to work. It moves the file (url) to the ~/.local/share/Trash/files/ and makes the info file to the ~/.local/share/Trash/info/ /2/, /3/.

          As there are the info files /4/ the KDE trash can system could show and restore them.


          /1/ With the Jaunty, ktrash --help
          Usage: ktrash [Qt-options] [KDE-options] [options] [ignored]

          Helper program to handle the KDE trash can
          Note: to move files to the trash, do not use ktrash, but "kioclient move 'url' trash:/"
          /2/ > freedesktop trash-spec
          /3/ or to the local /.Trash-1000/files/ & /.Trash-1000/info/. Trash settings !.
          /4/ They are text files with the .trashinfo extension. The trashinfo file has the path and deletion date.
          Before you edit, BACKUP !

          Why there are dead links ?
          1. Thread: Please explain how to access old kubuntu forum posts
          2. Thread: Lost Information

          Comment


            #6
            Re: Command line trash bin access

            Originally posted by Telengard
            The second option I found is trash-cli.

            Originally posted by features
            * Command line interface compatible with on of the rm command. You can alias rm with trash.
            * Remembers original path, deletion time and file permissions of each trashed file.
            * Compatible with the KDE trash.
            * Implements the FreeDesktop.org Trash Specification
            * Works with volume other than the home volume (e.g. USB pen or another partition).
            Sounds good, but it's not in the Ubuntu repos so I'd have to manually install. It's written in Python AFAIK.

            Does anyone have experience with either of these? Are there any disadvantages or pitfalls to using either of these in scripts? Is there a better solution?
            Which version of kubuntu are you using, trash-cli is available in jaunty repos

            Comment


              #7
              Re: Command line trash bin access

              Code:
              $ apt-cache search --names-only trash
              libtrash - A trash can library to use with LD_PRELOAD
              gnome-applets - Various applets for GNOME 2 panel - binary files
              $ lsb_release -a
              No LSB modules are available.
              Distributor ID: Ubuntu
              Description:  Ubuntu 8.04.3 LTS
              Release:    8.04
              Codename:    hardy
              I'm waiting for the next LTS to upgrade, thus skipping Jaunty and Karmic.
              Welcome newbies!
              Verify the ISO
              Kubuntu's documentation

              Comment


                #8
                Re: Command line trash bin access

                Originally posted by Telengard
                I'm waiting for the next LTS to upgrade, thus skipping Jaunty and Karmic.
                The only dependencies in the jaunty package are python (>=2.3) and python-support (>=0.7.1), so if your system meets the requirements, you can probably use the jaunty package in hardy as well (download the .deb manually and install)

                trash-cli is also available for hardy from a ppa repository:
                https://launchpad.net/~chameleondave/+archive/ppa

                Comment


                  #9
                  Re: Command line trash bin access

                  Originally posted by Rog131
                  The "kioclient move 'url' trash:/" /1/ seems to work. It moves the file (url) to the ~/.local/share/Trash/files/ and makes the info file to the ~/.local/share/Trash/info/ /2/, /3/.
                  . . .
                  /1/ With the Jaunty, ktrash --help
                  Rog131, sorry for missing your post before. It's good to know Jaunty has a similar command. I'll have to edit my OP to state explicitly that I'm on Hardy.

                  I've been using kfmclient move filename "trash:/" ever since opening this thread. So far it works fine. The only caveat so far seems to be that moving to trash seems to be much slower than deleting outright. It is to be expected, I suppose.
                  Welcome newbies!
                  Verify the ISO
                  Kubuntu's documentation

                  Comment


                    #10
                    Re: Command line trash bin access

                    Originally posted by kubicle
                    trash-cli is also available for hardy from a ppa repository
                    Thanks for pointing that out, but I don't see a need to install optional software when I can use kfmclient. What do you think?
                    Welcome newbies!
                    Verify the ISO
                    Kubuntu's documentation

                    Comment


                      #11
                      Re: Command line trash bin access

                      Originally posted by Telengard
                      Originally posted by kubicle
                      trash-cli is also available for hardy from a ppa repository
                      Thanks for pointing that out, but I don't see a need to install optional software when I can use kfmclient. What do you think?
                      Sure, use the tool that works the best for you, I was just bringing up the info as you brought up trash-cli as an option.

                      Although I'd think 'trash filename' is somewhat more convenient than 'kfmclient move filename "trash:/"', you can of course create a one-liner script to ease the usage of kfmclient.

                      As for me, I don't really use either (aliasing 'rm' to 'rm -i' has so far been enough for me), but the trash bin approach does have some appeal, so I just may give it a go.

                      Comment


                        #12
                        Re: Command line trash bin access

                        I found this thread really useful. I've just created the following shell script:

                        Code:
                        #!/bin/bash
                        #zap - move files to trash
                        
                        kioclient move $@ trash:/
                        saved it as /usr/local/bin/zap and run 'chmod +x /usr/local/bin/zap'. I can now 'zap' anything from the command line. What I particularly like is that this approach doesn't need to you add -r to delete directories: it moves directories to trash as most people would expect it to, instead of complaining as rm does.

                        Comment


                          #13
                          Re: Command line trash bin access

                          Thanks for the nice suggestions kubicle and olembe. I have come up with the script below. It is very similar to olembe's script, but reports what was done.

                          Code:
                          #! /bin/bash
                          
                          kfmclient move $@ "trash:/"
                          echo Moved to trash bin:
                          for filename in $@
                           do echo $filename
                          done
                          I put it in ~/bin/trash because it doesn't need to be system wide on my own computer. It works as expected, and trashed files may be restored from the trash bin gui, but it is very slow compared to rm.

                          Code:
                          $ time trash foo
                          Moved to trash bin:
                          foo
                          
                          real  0m20.274s
                          user  0m0.116s
                          sys   0m0.028s
                          I had thought to move each item separately and report each file name after moving, but that would multiply the trash access delay by the number of items. Three items or more would exceed 1 minute!

                          Code:
                          #! /bin/bash
                          #
                          #This would be way too slow! I'm using the first script in this post instead.
                          #
                          for item in $@
                           do kfmclient move $item "trash:/" && echo "trashed $item"
                          done
                          Welcome newbies!
                          Verify the ISO
                          Kubuntu's documentation

                          Comment


                            #14
                            Re: Command line trash bin access

                            I've started using trash - very simple, very quick. You got it in your repos? I can recommend it...
                            Once your problem is solved please mark the topic of the first post as SOLVED so others know and can benefit from your experience! / FAQ

                            Comment


                              #15
                              Re: Command line trash bin access

                              Telengard: that's a great addition! I've added it to my script now.

                              Comment

                              Working...
                              X