Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Nautilus script/extension for sorting trash by date deleted

  1. #1
    Join Date
    Apr 2008
    Beans
    231
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Nautilus script/extension for sorting trash by date deleted

    I'm interested in viewing the items in sorting the items in my trash folder by date deleted. I'm tired of waiting for Ubuntu to do this, and it seems like a simple enough task, so I'm wondering if there's any way to do it with a Nautilus script or extension.
    1. Has someone already written a script/extension to do this?
    2. Assuming no one has done so, will it be difficult to create one?

    I was unable to find any scripts or extensions for nautilus that would do what I want, so I'm going to assume one has not been written. I have a decent amount of experience in C++ and have written quite a few Perl scripts, so I figure I might be able to do this with some help.

    I can't imagine this being too difficult, because in the folder ~/.local/share/Trash/info/ there are data for each file in the Trash folder with the contents:
    Code:
    [Trash Info]
    Path=/path/where/file/was/located/when/deleted/file.ext
    DeletionDate=YYYY-MM-DDTHH:MM:SS
    Essentially all the script would have to do is create a hash of the filenames and deletion dates, sort them by deletion date, then output the filenames in the correct order. The problem is that I don't have any idea how to tell nautilus to arrange the files once I have the filenames in the correct order. Am I going about this the wrong way? Thanks for any help!

  2. #2
    Join Date
    May 2007
    Location
    ohio, usa
    Beans
    67
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Nautilus script/extension for sorting trash by date deleted

    For a while, I thought my trash was doing this, but then I realized that the dates I was seeing were the Last Modified dates. I think this is unusual and unexpected behaviour, especially for new users.

    Adding this functionality, even if only in a script, would be really beneficial. I'll try looking stuff up. I've only ever made simple scripts though, so if anyone else has any ideas it would help.

    __

    Edit: According to Ubuntu Package "trash-cli": "This package provides a command line interface trashcan utility compliant with the FreeDesktop.org Trash Specification. It remembers the name, original path, deletion date, and permissions of each trashed file."

    If these things are recorded there is definitely a way of doing this.

    This issue is also listed as a bug: https://bugs.launchpad.net/ubuntu/+s...us/+bug/301552
    Last edited by tk03759; July 3rd, 2009 at 05:04 PM. Reason: additional information

  3. #3
    Join Date
    Apr 2008
    Beans
    231
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Nautilus script/extension for sorting trash by date deleted

    Quote Originally Posted by tk03759 View Post
    Adding this functionality, even if only in a script, would be really beneficial. I'll try looking stuff up. I've only ever made simple scripts though, so if anyone else has any ideas it would help.
    It's nice to hear that I'm not the only one who wants this functionality.

    Quote Originally Posted by tk03759 View Post
    It remembers the name, original path, deletion date, and permissions of each trashed file."
    I actually mentioned this in my previous post. You can see the details of each file in ~/.local/share/Trash/info/.

    Quote Originally Posted by tk03759 View Post
    If these things are recorded there is definitely a way of doing this.
    Indeed. I have no doubt that it's possible to do; I just wonder if anyone who cares will ever do it. I'm sure I can write a Nautilus script which organizes the file names into the correct order. My problem is that I have no idea how to force the icons to organize themselves into that order. All I can do is output a list of the filenames in the correct order. If you think this could be useful I might actually write the script and upload it. Otherwise, I think we might need to mess with the source code of Nautilus to make this work.

    Quote Originally Posted by tk03759 View Post
    This issue is also listed as a bug: https://bugs.launchpad.net/ubuntu/+s...us/+bug/301552
    It's always nice to see a problem in the bugs list, but I doubt it will actually be implemented anytime soon. I've been waiting for this to be fixed ever since I first started using Ubuntu. Anyway, it's more of a feature request than a bug.

  4. #4
    Join Date
    Apr 2008
    Beans
    231
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Nautilus script/extension for sorting trash by date deleted

    I wrote a Perl script which organizes the files by date deleted and prints a list. I'll attach the script to this post and also paste it below. If anyone knows a way to use the output of this file to control the order in which Nautilus places the files please let me know.

    Code:
    #!/usr/bin/perl
    use warnings;
    use strict;
    
    # Create an alphabetical listing of all the files and folders in the Trash
    my @files = `ls ~/.local/share/Trash/files`;
    
    # Create a hash to store the corresponding DeletionDates to each file
    my %file_hash;
    
    # Iterate once for each file in the array
    for(my $i = 0; $i <= $#files; $i++)
    {
    	# Remove all linebreaks and replace all " " with "\ "
    	$files[$i] =~ s/\n//g;
    	$files[$i] =~ s/ /\\ /g;
    	
    	# Find the trashinfo for the current file
    	my $fileinfo = `cat ~/.local/share/Trash/info/$files[$i].trashinfo`;
    	
    	# Uncomment the next line for the output to use " " instead of "\ "
    	#$files[$i] =~ s/\\ / /g;
    	
    	# Extract the DeletionDate from the trashinfo of the file
    	# The following three lines could probably be condensed into one or two
    	my $DeletionDate = $fileinfo;
    	$DeletionDate =~ s/DeletionDate=(.+)/$1/;
    	$DeletionDate = $1;
    	
    	# Store the information in the hash for later use
    	$file_hash{"$DeletionDate"} = $files[$i];
    }
    
    # Sort and print the files in the hash
    # Note: This will sort the files from OLDEST TO NEWEST
    foreach my $key (sort (keys(%file_hash)))
    {
    	print("$file_hash{$key}\n");
    }
    
    
    # USE FOR DEBUGGING TO PRINT A PRETTY HASH
    #foreach my $key (sort (keys(%file_hash))) {
    #	print "\t\t$key \t\t$file_hash{$key}\n";
    #}
    Attached Files Attached Files

  5. #5
    Join Date
    Jul 2007
    Location
    Ohio, US
    Beans
    287
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Nautilus script/extension for sorting trash by date deleted

    @Altay: The package tk suggested is "trash-cli" which is a command line tool seperate from what you are talking about. It has more features than what you can find in the trash/info folder. More here and here.

    There is also some code used in KDE in this bugreport..
    Cheers!
    Last edited by sancho panza; August 7th, 2009 at 03:45 PM. Reason: Added some more links
    Maverick Thinkpad T61, Intel GMA X3100, Intel WiFi 4965AG.

  6. #6
    Join Date
    Jul 2007
    Location
    Ohio, US
    Beans
    287
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Nautilus script/extension for sorting trash by date deleted

    I've listed a set of bugreports here.

    Maybe someone who knows coding can put something together using the KDE bugfix mentioned in the last post and/or the trash-cli program?
    Maverick Thinkpad T61, Intel GMA X3100, Intel WiFi 4965AG.

  7. #7
    Join Date
    Nov 2007
    Location
    Ottawa, Canada
    Beans
    21
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Nautilus script/extension for sorting trash by date deleted

    I just ran into this myself and my searching lead me here. Anyway, after a bit of experimenting, here are a couple of quick and easy commands, from the shell, that will likely give you what you're looking for:

    $ ls -cltr ~/.local/share/Trash/files

    (if you have trouble remembering the list of options, think of how you want to sort through your "clutter"..heh .. of course, you could just make it a command alias in your shell like 'showtrash' or something like that)

    OR

    $ grep -hB 1 yyyy-mm-ddThh ~/.local/share/Trash/info/*

    For example grep -hB 1 2009-09-06T14 ~/.local/share/Trash/info/* will list files deleted September 6 between 2:00 and 2:59 pm.

    I agree, though: a "date deleted column" in Nautilus would be ideal.
    Last edited by Krallus; September 6th, 2009 at 08:05 PM.

  8. #8
    Join Date
    Jul 2007
    Location
    Ohio, US
    Beans
    287
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Nautilus script/extension for sorting trash by date deleted

    Thanks for the tips, but these commands only sort them by date, but offer no way to delete them. How can I do that? Also, I doubt if the "ls" command you suggested sorts files by date deleted. I think it sorts them by modif/access date, which may not be the same as the delete date.

    You could go to the bugreports I listed in my earlier post and push for this feature to get included. It is already implemented in KDE.
    Maverick Thinkpad T61, Intel GMA X3100, Intel WiFi 4965AG.

  9. #9
    Join Date
    Nov 2007
    Location
    Ottawa, Canada
    Beans
    21
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Nautilus script/extension for sorting trash by date deleted

    The ls command I mentioned will sort by "ctime" (time of last modification of file status information) which includes when the file moved to its current directory, if that was the last change to the file status. This use of the command presumes that the last change to the files of concern is the move to the trash folder, which I think is a reasonable assumption.

    Deleting is something else .. though you could some funky things with chaining commands to delete a subset of the generated list, but I haven't bothered to figure out what that would be as, in my case, I just wanted to know the last couple of files I moved to the trash (and then changed my mind about), then looked for them by filename in the trash GUI and restored them.

    I'll definitely bump the feature request.

  10. #10
    Join Date
    Jul 2007
    Location
    Ohio, US
    Beans
    287
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Nautilus script/extension for sorting trash by date deleted

    There seems to be some incremental progress here. Screenshot is attached.
    I could not get it to compile on my system as I'm a not familiar with checking dependencies and stuff. If others could help bump the bug, that might help.

    Cheers,

    Maverick Thinkpad T61, Intel GMA X3100, Intel WiFi 4965AG.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •