Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2009/01/23

Considering del ...

Here is a shell-script replacement for rm. As you know, rm just kills a file or directory outright. Often this is what we want. But every windowing system I know uses an intermediate Trash Can, a place to store your deleted files in case you say "No, I really wanted that directory full of L0Lcats".

So, the question is, how do I get that functionality in your command line? They call it del, but I prefer trash, as del on Windows doesn't put it in the Trash Can, it blows it away.

Anyway, the code:

# !/bin/bash
# http://ubuntuforums.org/showthread.php?t=124137&highlight=trash
mv -vi -- "$@" $HOME/.Trash


Problems. When I tried this, the file was moved to .Trash, because there was no .Trash dir. Why was there no .Trash dir? Because with Ubuntu Intrepid (and I have no idea when things changed), the Trash dir is $HOME/.local/share/Trash/. Specifically, there's $HOME/.local/share/Trash/files/, which holds the actual files and directories, and $HOME/.local/share/Trash/info/.

Let me show you a sample *.trashinfo file.

[Trash Info]
Path=/home/jacoby/Desktop/SyntaxHighlighter_1.5.1.rar
DeletionDate=2009-01-23T10:07:19


For each file and directory in the files directory, there's a .trashinfo file saying when it was deleted and where it restores to. So, obviously, the del/trash script is not up to the task of today's Gnome trashing. But what to do about it? More later, as I consider the problem set.

4 comments:

  1. Seems pretty simple to duplicate what Gnome is doing...all you're doing is putting `pwd` and a formatted date into a text file with some reference text...unless I'm missing something specific about those *.trashinfo files...

    ReplyDelete
  2. That's about what I'm thinking. I'm a Perl guy, so whatever I do, I'll do in Perl, but yeah, should be a simple piece of code. Code I can't dive into right now, because I should be considering dumping big tab-delimited files into R, but yeah.

    But not as simple as moving to .Trash. Which I think should be .Trash/ anyway.

    ReplyDelete
  3. That'd be far too simple and make too much sense. OpenSource projects tend to be way too much like some kind of Computer Science experiment gone wrong...everything has to be insanely overcomplicated until things start to look like Windows (eek!)

    Coincidentally I just packaged and pushed R 2.8.1 to all the ITaP labs last week :)

    ReplyDelete
  4. That's cool. R is a cool and wonderful thing, but on occasion, it is stupid. For example, last year, I was working on a project to take data and use Perl to call R on a big Solaris machine to batch-create Quality Control graphs. Wanted to dump 'em to a web-friendly place, so we wanted JPG or PNG. But for R to make an image, it wanted X. It worked fine when I would ssh in, but not when I put it in cron.

    I had to have it write to postscript and convert ps to jpg, with annoying image degradation.

    And yeah. I run Gnome, and the Gnome of 2009 is scarcely recognizable from the Gnome of 2000.

    ReplyDelete