• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to empty Trash through command line in Ubuntu

June 21, 2013 by Sharad Chhetri 5 Comments

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.

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to upgrade ubuntu 12.10 to 13.04 through command line
  2. How to configure static ip address through command line in Ubuntu
  3. How to upgrade Ubuntu 13.04 to 13.10 by command line
  4. Install XFCE Desktop in Ubuntu through command line
  5. How to zip the directory in linux with command line
  6. Eject Command: Eject DVD-ROM Or CD-ROM In Linux
  7. How to see line numbers in file through cat command
  8. Convert video file into gif file through command line in linux
  9. Convert new line to space by using sed command
  10. search keyword in file with line number using grep command

Filed Under: Linux, Tips And Tricks Tagged With: ubuntu

Reader Interactions

Comments

  1. daniel says

    July 2, 2016 at 5:19 am

    This does not removed the files in “expunged” folder …

    Reply
  2. twet says

    November 26, 2014 at 12:22 pm

    Hi,

    I followed the steps but I only have a blinking cursor at the end. What should I do?

    Reply
    • sharad chhetri says

      November 26, 2014 at 3:22 pm

      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

      Reply
  3. walt says

    December 27, 2013 at 10:57 pm

    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.

    Reply
    • sharad chhetri says

      December 28, 2013 at 4:48 am

      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,

      sudo su -
      ls -1d /home/* |while read abc;do ls -la "$abc/.local/share/Trash/files/";done
      

      To remove

      ls -1d /home/* |while read abc;do rm -fr "$abc/.local/share/Trash/files/";done
      

      (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

      for i in partiton2 partition3;do find "$/i" -name Trash >> trash_path;done
      

      This will list in which partition the Trash exist to which users of that particular Operating system

      for i in `cat trash_path`;do ls -la  "$i/files";done
      

      Note: I just write dirty bash script one liner. Before removing anything, first check. Modify the script as per your Operating system.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

How to see line numbers in file through cat command

Convert new line to space by using sed command

How to increase Password Expire date without resetting the password

How to configure ethernet in CentOS 6 after installing in Virtual Box

Terminal Recording with script and scriptreplay command

Recover Linux Grub Password in linux rescue mode CentOS/Red Hat

How to install pam_mysql in CentOS or Red Hat

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy