andreafrancia / trash-cli

Command line interface to the freedesktop.org trashcan.
GNU General Public License v2.0
3.63k stars 177 forks source link

Add (optional) disk usage information on `trash-list` #149

Closed eloyesp closed 3 years ago

eloyesp commented 5 years ago

It would be awesome to add disk usage information on trash list to help when disk is getting full what the problematic file could be.

ghost commented 5 years ago

@eloyesp Why not just use ncdu?

antofthy commented 5 years ago

@billop 1/ not everyone has ncdu (non-standard) 2/ It is not even that good (can't read normal du output from a remote system) 3/ it's not very user friendly with regards to the desktop trash which uses randomly generated filenames (to protect again unusual filenames), and keeps trashed directories together as complete unit.

That last is also why it is a BAD idea to use 'find' to delete older files in the desktop trash. Basically you need more smarts than normal system utilities, and why I am upvoting this request myself.

eloyesp commented 5 years ago

@billop I didn't know about ncdu, I've been using that now and it's great.

On the other hand, adding to what @antofthy mentions, I'm not sure what would happen with the corresponding .trashinfo files when I remove files manually.

antofthy commented 5 years ago

The problem is find will remove old files that were already in the directories just trashed. That is you trash a directory with some old files it in. Next 'find' run and those old files get removed, even though the directory was just trashed! Basically Trashcan is designed to not only keep a backup of files, but keep a backup with there original file meta data, including age!

Find is a bad idea...

From the trashcan spec ...

If a directory was trashed in its entirety, it is easiest to undelete it or remove it from the trash only in its entirety as well, not as separate files.

For DU alternatives (many better than "ncdu") see http://www.ict.griffith.edu.au/anthony/info/apps/du.txt

My notes on CLI trash utilities, updated as I learn more... http://www.ict.griffith.edu.au/anthony/info/misc/trash.txt

ghost commented 5 years ago

For DU alternatives (many better than "ncdu") see http://www.ict.griffith.edu.au/anthony/info/apps/du.txt

So I looked at that list but it seems like ncdu is the only notable ncurses tool. Unless you were talking about the GUI alternatives, which I personally like filelight for but I personally prefer ncdu these days.

antofthy commented 5 years ago

My main problem with just about EVERY du graphing utility, is they don't accept standard 'du' output! I often do a du into a text file, transfer it to my workstation so I can then use a graphical du viewer. ncdu is pretty good, but I don't want to try to install it on 800+ machines of all sorts of OS's and versions, where 'du' is on all of them!

If accepts raw 'du output you also have the option of displaying other information. There is a nice one liner to get just file counts in directories rather than file sizes! It is even good for reporting mysql database sizes!

andreafrancia commented 3 years ago

Fixed in b3e0592

Simply use the hidden --size option of trash-list.

$ ./trash-list --size
0 /Users/andrea/trash-cli/foo
4 /Users/andrea/trash-cli/bar

You need to install trash-cli from sources or wait for the next release.

antofthy commented 3 years ago

Why is it even 'hidden' then? Especially a it is a very useful option!

In which case this issue should be re-opened until it is documented!

However the size appears to be as per gio list -l trash:// which is unrelated to kbytes, or even disk blocks! As such it is un unknown quantity, and only useful to see which trash group is 'larger'.

# trash-list --size
90 /home/anthony/test
# gio list -l trash://
test    90      (regular)
# du -h ~/.local/share/Trash/
8       /home/anthony/.local/share/Trash/info
8       /home/anthony/.local/share/Trash/files
20      /home/anthony/.local/share/Trash/

The above test was with only one item in trash, so should be realistically 'similar'. And that is a single 'very small' file of 1 disk block of 4Kbytes, + 4K for the info file, 4K for each directory (3). So I have no idea what that '90' means!

andreafrancia commented 3 years ago

Why is it even 'hidden' then? Especially a it is a very useful option!

Because I found the time to implement it and I don't have found the time to document it. Do a pull request if you care enough.

andreafrancia commented 3 years ago

And the other reason is that I need some time to decide if it is a good idea to keep it and to keep it implemented like at it is implemented.