I use trash-put to trash files from command line. Recently, I had aliased my rm command to trash-put so that I don't accidentally delete something important.

However, what happened now was that I had to delete some files from my /var/log folder to free up some space on the / filesystem. I did this using sudo:

sudo rm /var/log/somelog

#Above command is equivalent to: 
sudo trash-put /var/log/somelog

After doing this, there was no free space recovered on the partition since the files must have moved to some trash-can. However, when I checked my trash-can there were no files. I tried to see if there was .Trash-100 folder on the / partition, but even that was not there.

So, where did my trashed file go? And how do I find it so that I can decimate it to recover some space?

  • 4
    Alias expansion only works for the first word of a simple command. In sudo rm ... the rm is not subject to alias expansion, so your alias is not applied. For the shell, the rm in sudo rm is a parameter to sudo and as such not different from the rm in /bin/echo rm. – Dubu Jun 12 '15 at 11:07
  • 1
    @Dubu Yes. You are right. The file was never sent to any trash. It was indeed deleted. And as I found using lsof (as suggested in the accepted answer), it was being used by some process, and hence the space was not released. – shivams Jun 12 '15 at 11:09

Those files you removed may actually still be opened by another process. In that case the file space will become available when that process closes it's handle to the file.

You can lookup these files with lsof:

lsof |grep "var/log"|grep deleted
  • Indeed, this seems to be the case. Both of the deleted files show up in the lsof listing. I'll do some more investigation and then mark your answer as accepted. – shivams Jun 12 '15 at 10:36

Aliases will not be invoked when using sudo:

$ alias a=ls
$ sudo a
sudo: a: command not found

This means that the files were actually deleted rather than moved to some trash can.

If there are processes who are still keeping the files opened, e.g. for writing to them, then the space used by the files will not be reclaimed until those processes have either closed the files or exited.


According to trash-put manpage, trash-put puts the files on the trash, which is defined by the FreeDesktop.org Trash Specification.

In chapter Trash directories, Trashing follows such fallback process:

  1. Home trash, located in $XDG_DATA_HOME/Trash. In your case, it may be /root/Trash for root. It's also possible that sudo passed $XDG_DATA_HOME through, so also try looking for it under your own trash. It is the main trash used.
  2. For directories not sharing the same mount root as $XDG_DATA_HOME, a trash in the top directories of the mounted directories may be used.
    1. $topdir/.Trash/$UID may be tried first.
    2. If the test fails (e.g. $topdir/.Trash doesn't exist), use $topdir/.Trash-$UID. In your case, try looking for it in /.Trash-0, since sudo makes your UID root.


Binging 'root trash' gives me more.

From a really old tutorial which mentions gksudo nautilus '/root/.Trash/', the .Trash (instead of Trash as in fd.o) directory under root's $XDG_DATA_HOME may be a good option to start with.

According to a really old question in Chinese in which .Trash-root is created for the asker's removable disk, some implementations use username instead of the numeric UID.


As it was pointed out in a comment and in an answer, the problem is with the expansion of your alias.

But there are solutions for this:

If you want sudo to work with all your aliases (and thus circumvent the problem pointed out by @Kusalananda), you can add the following alias to your alias file:

alias sudo='sudo '

Had you done this, sudo rm would have been expanded to sudo trash-put as you expected.

To answer the comment from @Dubu about aliases only working as the first word of a command: if you add the flag -g to an alias definition, it will become global and work even if not in the command position. You could have done this with your rm alias. However, you probably don't want to have other bad surprises with sudo, so the first method is more appropriate here. This one is more relevant if you want, for example, to set an alias for a piped command (e.g. alias -g pl='| less').

As for the location of the trash when using trash-cli with sudo, @Arthur2e5 answers this. I simply can add that, in my case, the location is:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.