5

Last time I trashed a file

$ pwd
/tmp/test
$ trash mfile 
trash: cannot trash regular file `mfile'
$ sudo trash mfile 
$

and the file went into

$ sudo ls /.Trash/0/files -la
total 12
drwx------ 2 root root 4096 May 19 16:52 .
drwx------ 4 root root 4096 May 19 16:52 ..
-rw-rw-r-- 1 t    t       6 May 19 16:48 mfile
  1. Now I can't empty the trash:

    $ sudo trash-empty 
    $ sudo ls /.Trash/0/files -la
    total 12
    drwx------ 2 root root 4096 May 19 16:52 .
    drwx------ 4 root root 4096 May 19 16:52 ..
    -rw-rw-r-- 1 t    t       6 May 19 16:48 mfile
    

    How can I empty the trash?

  2. I can't list the files in that trash either

    $ sudo trash-list
    [sudo] password for t: 
    TrashDir skipped because parent not sticky: /.Trash/0
    

    Thanks.

2
  • 2
    What's wrong with sudo rm /.Trash/0/files/mfile? Commented May 22, 2018 at 23:15
  • @roaima The idea is to check what files are in the trash bin of all partitions and selectively remove or restore certain one.
    – Wang
    Commented Apr 25, 2019 at 16:15

2 Answers 2

3

I believe the root cause of this problem is that when a Trash folder is created for a mounted partition it can be created without the sticky bit set. This appears to be the case when mounting to any of the "system_internal" mount paths There have been bugs reported regarding this problem against trash-cli and a workaround of adding a secret --trash-dir option to trash-empty in commit (2a83ed5) was added to allow trash-empty to empty a specified directory bypassing the sticky bit check. This clue leads us to the simplest solution. Simply set the sticky bit on the Trash folder in question with the command chmod +t /mount/point/.Trash This allows trash to function as intended. I've tested this approach on partitions mounted at /srv and /home and /media/$USER/VolumeName on Ubuntu 16.04 and Ubuntu 18.04 and the results were successful as expected. I would expect this approach to work on other `nixes as well.

Note: This approach won't work on filesystems that don't support setting the sticky bit such as NTFS and FAT but works great on EXT2/3/4 filesystems.

Here's a list of those "system_internal" mount paths:

 "/",              /* we already have "Filesystem root" in Nautilus */ 
    "/bin",
    "/boot",
    "/compat/linux/proc",
    "/compat/linux/sys",
    "/dev",
    "/etc",
    "/home",
    "/lib",
    "/lib64",
    "/libexec",
    "/live/cow",
    "/live/image",
    "/media",
    "/mnt",
    "/opt",
    "/rescue",
    "/root",
    "/sbin",
    "/srv",
    "/tmp",
    "/usr",
    "/usr/X11R6",
    "/usr/local",
    "/usr/obj",
    "/usr/ports",
    "/usr/src",
    "/usr/xobj",
    "/var",
    "/var/crash",
    "/var/local",
    "/var/log",
    "/var/log/audit", /* https://bugzilla.redhat.com/show_bug.cgi?id=333041 */
    "/var/mail",
    "/var/run",
    "/var/tmp",       /* https://bugzilla.redhat.com/show_bug.cgi?id=335241 */
    "/proc",
    "/sbin",
    "/net",
    "/sys",

Sources:

https://github.com/andreafrancia/trash-cli/issues/65

https://www.linuxquestions.org/questions/linux-desktop-74/how-do-empty-view-trash-files-on-mounted-volumes-899188/

https://en.wikipedia.org/wiki/Sticky_bit

0

Just remove it with the rm command including the -r and -f switches. These will delete directories (r) and symbolic links (f) to any trashed files.

rm -rf /.Trash/0/files/*

Don't forget the glob expansion (*) otherwise you'll delete the trash directory.

echo "alias empty='rm -rf /.Trash/0/files/*'" >> ~/.bashrc

This makes an alias so now you can empty the trash with the command empty.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .