Trash Problems and Solutions*
* This guide was originally prepared under the title: Disk Full? - Check Your Trash Bin(s). I wrote a subsequent guide dealing specifically with lost 'free' space and how to restore it. That guide can be found at: Disk Space Problems & Solutions
In a Rush and Sure It's a Trash Problem? Go Directly to #6 ...
1. Error Messages - Why You Are Here?
"There is not enough room on the disk to save ..." Perhaps you received an error message. Maybe you have tried but cannot delete the contents of the Trash bin. Perhaps you looked at your system files and realized that you were running out of disk space. Emptying the trash has been a tradition throughout the world since long before computers were invented. Over time we sometimes forget to do perform this important task.
With computer trash, you have to not only remember to delete, you must know how to do it. If you cannot explain why you are running out of hard drive space, it may be because you haven't emptied the trash - properly, often enough, or perhaps both! Read on.
2. Shrinking Free Space - Common Causes
- Undeleted trash.
- If you believe the cause of your problem is not a trash issue but your free space has unexpectedly decreased, please go to Disk Space Problems & Solutions.
3. Checking Your Partition
Here are some of the many ways to check your free space. Each has its advantages. Use the one or combination you like the best.
- df -Th | sort (Terminal)
Note: "sort" will order the partitions alphabetically. The "T" switch shows the file type - you can omit it if desired. If used, ntfs partitions will show type: "fuseblk".Code:/dev/sda1 ext3 23G 9.6G 12G 46% / /dev/sda2 ext3 34G 2.1G 30G 7% /home /dev/sdg2 fuseblk 965M 5.4M 960M 1% /media/test Filesystem Type Size Used Avail Use% Mounted on
- Gnome-Device-Manager (GUI)
System, Administration, System Monitor (gnome-system-manager)
Code:Device Dir Type Total Free Available Used % /dev/sda2 /home ext3 33.1GiB 31.1GiB 29.4GiB 2.0GiB 6%
- Disk Usage Analyzer / aka Baobab (GUI)
Applications, Accessories, Disk Usage Analyzer.
This is a graphical app that displays hard drives and partitions.
While DUA is a valid tool, it often brings up questions about its use. Here are a couple of things to keep in mind:
- One common question is why DUA seems to show twice as much space as the partition contains. By default DUA It displays the .gvfs (gnome virtual file system) folder contents. To get an accurate picture of the actual/physical contents, uncheck ".gvfs" via Edit, Preferences.
- The top directory will always show 100% full. The percentages of all the folders adds up to 100%. It does not mean there is no space left on the drive/partition.
- Find Large Files
If you think you might have one or more large files taking up space, you can search for large files with the following commands. If you want to decrease the search file size, replace 'G' (gigabyte) with 'M' (MB). An initial installation will not have files larger than 500MB on the partition. Examples:
Code:sudo find / -name '*' -size +1G sudo find / -name '*' -size +500M
4. Trash Characteristics
Under normal circumstances, only files/folders deleted with the terminal "rm" command or via the Shift-Del key combination in file browsers such as nautilus or thunar are immediately erased - freeing up disk space. The rest go to a trash bin, where deleted materials remain until the bin(s) are emptied.
The Trash folders are hidden. If using the "ls" command in the command line, you must include the "-a" switch (ls -a). In nautilus or other file browsers, you must have "view hidden files" enabled (nautilus = Ctrl-H).
There are two folders within the Trash bin - "info" and "files".
- info: The "info" folder contains information regarding the files contained in the "files" folder. Each deleted file has an entry in the "info" folder, containing the deletion date and path.
- files: This folder contains the actual deleted files.
5. Why Must I Delete Trash?
Until the trash bins are emptied, deleted items continue to take up disk space just as a normal files do. The space containing these deleted items cannot be used as long as the deleted files reside in Trash bin(s).
If you want proof, find a suitably large file and make a copy of it. Using any of the methods above, review the free and used disk space and then delete the file via a file browser or right click/remove in a file browser. Recheck the results. You will notice the used and free space have not changed. The reason is because the deleted files in a Trash bin are still intact - they have only been moved to a different folder.
6. Okay, Where Are the Trash Files?
Here is where these files normally reside.
- ~/.local/share/Trash User's Trash (hardy and later)
- ~/.Trash User's Trash (pre-hardy)
- /root/.local/share/Trash System Trash (hardy and later)
- /root/.Trash System Trash (pre-hardy):
- /.local/share/.Trash-1000 NTFS/FAT32/etc: Trash deleted in these partitions is placed in a Trash bin named in accordance with the user deleting the file, e.g. -1000, 1002, -0, etc
In a file browser, typing "trash:/" in the location window will take you to the user's trash folder.
All system trash, regardless of where it resides, by default contains the name "Trash". Here is a command that will greatly simplify your task. It seeks out all folders on your system that contain either "trash" or "Trash" while eliminating other files such as "trashapplet". It must be run with root privileges since it will be searching the system files. It does not require root privileges to be run on your home partition. It searches your entire system, so it may take a few minutes. Note: Since it finds any folder named Trash, it might find other non-system trash folders as well (such as an Evolution trash folder).
Code:sudo find / -type d -name *Trash*
- Here is an example run on my computer:
Code:~/Desktop: sudo find / -type d -iname *Trash* | grep Trash /media/data/.Trash-1000 ~/.local/share/Trash /home/.Trash-0 /root/.local/share/Trash
7. How Do I Delete Trash and Free Up Space?
- The Safe Way: File Browser with Administrative Powers
- gksudo nautilus (Terminal)
- Do not use "sudo". Sudo is meant to be used for terminal commands and processes. This command, even though run in terminal, will open a gui application. "gksudo" is the appropriate command.
- You can start nautilus with the folder path ( gksudo nautilus ~/.local/share/Trash ) It is necessary to navigate to each Trash folder to delete it's contents.
- Note: If gksudo nautilus does not work, forum member SATXan reports in Post #31 that the following command might work: gksudo dbus-launch nautilus
- Use Shft-Delete to delete individual folders/files. Confirm the "permanent delete" message. If you just hit the Delete key, the folders/files will be deleted and moved to the .... Trash/files folder! If you delete the parent Trash folder, this is not necessary. A simple press of the Delete key will remove the Trash folder and subfolders.
- You may delete the entire Trash folder. It will be created the next time an item is deleted.
- Nautilus also can delete trash directly, bypassing the Trash bin.
- Edit > Preferences > Behavior tab > Trash
- Include a right click option which allows a delete command which bypasses Trash
- The Efficient Way: Command Line (with "chown" when required)
- Using the Terminal. By using commands in terminal you can quickly delete all user-owned Trash folders. Using the command line combines ease of use with a bit of risk.
You must ensure you have correctly input the command. Files deleted with the "rm" command are generally NOT recoverable!
- To delete your Trash contents in your home folder:
Code:rm -rf ~/.local/share/Trash/*
- To delete root's Trash contents in your home folder:
Sometimes root trash ends up in your local Trash bin. You cannot delete this without administrative powers. To accomplish the task, use "sudo" to change ownership of the Trash folder contents to the user, then delete the folder as above:
Code:sudo chown -R username ~/.local/share/Trash rm -rf ~/.local/share/Trash/*
- To delete root's Trash contents in root's Trash bin:
I recommend using nautilus or another file browser, opened with root privileges, to accomplish this task. Using the command line to delete system Trash is safe only if the command is entered properly. A mistake could possibly erase system files and render the system unusable.
There are commands which will directly delete root trash using "sudo rm -rf" but I will not reproduce them here. A safer method is again to change the ownership to yourself and then delete the Trash. Of course, if you enter the wrong commands twice you can still destroy your system...
We will again use "sudo" to change ownership of the Trash folder contents to the user and then delete the folder as previously:
Code:sudo chown -R yourusername /root/.local/share/Trash/ rm -rf ~/.local/share/Trash
8. How to Make Trash Bins on NTFS / VFAT Partitions
A trash bin may automatically be created on NTFS and vfat partitions. It will be named by the UID of the user who deletes the trash - for example, .Trash-1000. Note that these are hidden folders (they begin with a . )
If you wish to create a trash bin in a non-Linux partition:
- In fstab, add "uid=<uid number>,gid=<gid number> to the partition options.
Example for a user with the UID of 1000 on a partition mounted at /media/myfiles (Note you can check with the "id" command in a terminal):
UUID=8797e97ew8790q87e907q /media/myfiles ntfs auto,users,umask=027,utf8,uid=1000,gid=1000 0 0
- Create the trash folder in the specified partition. Example on a partition mounted as /media/myfiles:
- Reboot or umount/mount the specified partition.
9. A Few Tips About Trash
- If your user Trash icon is not displayed on the Desktop, try this. Change the value to "false" to hide it.
Code:gconftool-2 --type bool --set /apps/nautilus/desktop/trash_icon_visible "true"
- If the .Trash-1000 (or user's uid if different) folder exists in ntfs/fat32 partitions the contents should be displayed in the user's Desktop Trash bin.
Other Useful Trash-Related Links:
HOWTO: Cleaning up all those unnecessary junk files
HOWTO: Automatically regulate the size and age of your Trash folder
A send-to-trash command for the shell. aa