How to empty Trash through command line in Ubuntu
Operating System : Ubuntu 12.10 n l
I checked this practical in Ubuntu 12.10 n l .
To empty the trash in Ubuntu through command line follow the given steps
Step 1 : First check is Trash folder exist. By ls -la command you can see other files and folders inside Trash dir.
linux@tuxworld:~$ ls -la ~/.local/share/Trash/ total 20 drwx------ 5 linux linux 4096 Jul 17 2012 . drwxr-xr-x 28 linux linux 4096 Jun 21 20:36 .. drwx------ 2 linux linux 4096 Apr 2 07:51 expunged drwx------ 2 linux linux 4096 Jun 18 21:02 files drwx------ 2 linux linux 4096 Jun 18 21:02 info linux@tuxworld:~$
Step 2: Now change to directory files.
cd linux@tuxworld:~$ cd ~/.local/share/Trash/files ls -la ~/.local/share/Trash/files
Step 3 : Now remove all files and directory inside ~/.local/share/Trash/files
rm -fr ~/.local/share/Trash/files/*
Now check Trash in Desktop, it would be empty now.
This does not removed the files in “expunged” folder …
Hi,
I followed the steps but I only have a blinking cursor at the end. What should I do?
Hello twet,
Can you provide the output of following commands.
(1) ls -1 ~/.local/share/Trash/files|wc -l
(2) cat /etc/issue
(3) echo $SHELL
What would be the command to empty ALL trash files, including the ones that are in other partitions, and other drives, and USB stick etc.? Can this be done with one single command, since the trash icon shows full whenever there is trash in partitions as well as the local trash area.
Thank you in advance.
Hello Walt,
Yes it is possible but in this case you have to make script for it.
Reason:
(1)By-default the trash directory exist to User’s Home directory. In a single installed Operating System you may have many users hence rather than going to each user’s home directory. We can create a script. For eg. Our all user’s home directory path is in /home then you can use this loop command.
First check,in which user’s home dir Trash exist. This command not only help to show existence of Trash but we can also see is our command okay to run.
login as superuser,
To remove
(2) Now second scenario is with different partition, I am assuming multiple Ubuntu booting system. In this case the running operating system must have these partition in some mounted dir. Which you can see by running command
df -Th
You have to just change the script or one liner command and give absolute path of mounted partition.
for eg. you mounted other filesystem and now mounted dir. are like this
/partition2 /dev/sda2
/partition3 /dev/sda3
This will list in which partition the Trash exist to which users of that particular Operating system
Note: I just write dirty bash script one liner. Before removing anything, first check. Modify the script as per your Operating system.