Trash can on linux

How can I empty the trash using terminal?

I am not able to find trash anywhere. Can you please tell me a command or anything like that to empty the trash using terminal ?

This was posted 3 years ago. We need something that spells this out including what version it works for here in 2017

5 Answers 5

You can use the rm command:

The rm command removes (deletes) files or directories.

-f, --force Ignore nonexistant files, and never prompt before removing. -r, -R, --recursive Remove directories and their contents recursively. 

The trash folder is found at: $HOME/.local/share/Trash

Be careful how you use the rm command — the files aren’t sent to a trash can where you can undelete them, so it’s not easy to undo.

Sensitive system folders and files cannot be removed without privileges, and rm cannot remove folders at all, unless you give it the -r (or equivalent) option. However using rm without proper care may case loss of lost of important personal files, especially if used with wildcard arguments.

Trash directory has three directories in it. 1) expunged 2) files 3) info Expunged is empty, files have files as shown in trash bin while info has all file names with extension .info Should I follow the above method which will remove these three directories or should I just remove from files and info directories.

Deleting this broke my trash bin: after doing it, I couldn’t send files to trash anymore (couldn’t write to ~/.local/share/Trash/info/*.trashinfo)

After you sudo apt install trash-cli , you can do

More interesting details about trash handling below and in the man page.

restore-trash (1) - Restore for Command line trash utility. trash (1) - Command line trash utility. trash-empty (1) - Empty for Command line trash utility. trash-list (1) - List trashed files. trash-put (1) - Command line trash utility. trash-rm (1) - Removes files matching a pattern from the trash can 

This is the correct answer. If you have an USB stick in, for example, the files you trash in it will be put in an hidden directory in the root of the device (at least it happened last time I checked) .Trash-$UID — so in this case the trash is physically in two different places.

So sad that you have to install a package just to empty the trash. Counting the trash against the disk space is one of the most annoying features of Ubuntu.

Читайте также:  Linux scp remote server

@Michael «Trash» is a feature provided by the desktop manager, which is a layer above the stuff that you would usually use in the command line. Really all it does is move files into a hidden folder on the same device, and store some metadata so they can be put back into place if the user would like. You don’t actually reclaim any space until you «empty» the trash, which is when the file is actually deleted.

It should be noted that this command is user specific. I installed it and was scratching my head about why it wasn’t working til I realized the files were in the trash of another user.

I find it helpful to run baobab as sudo so one can inspect all the trash bins across users and devices. I’ve had it happen a few times that files were in root ‘s trash, which would not get deleted when the user emptied the trash.

You are looking for the $XDG_DATA_HOME/Trash directory. The trash directory is defined in the «Desktop Trash Can Specification» of the freedesktop site. This variable is normally not available in the terminal windows, hence you will need for trash-empty . This command follows all the specification of the Freedesktop.org and it’s intelligent enough to find out where the Trash is. You will need to install it first.

There are other tools for this, like gvfs-trash —empty which can also send items to the Trash can.

@Braiam Can you please elaborate more? How can I use it? I am not getting how it is solving my purpose. Please explain a little bit. And I don’t want to trash the items, I want to empty the trash.

@hellodear2 trash-empty empties the trash. You only need to run it. The binary is in the trash-cli package. Is the same as jhort solution just that I explain where it comes from and offer another tool.

Источник

How to Put the Trash Can on the Desktop in Ubuntu 22.04

This is handy, and evokes the old Unity launcher which had a trash can icon on it (right at the bottom). But not everyone wants it back there, on screen, all of the time.

Ubuntu 22.04 gives you a small set of dock settings, including a toggle to remove the trash can from the Ubuntu Dock entirely.

What there isn’t an option for is to show the trash can on the desktop again.

To put the trash can back on the desktop (even if you also have it on the dock) run the command:

gsettings set org.gnome.shell.extensions.ding show-trash true

Immediately after hitting enter on this command the trash can icon will boop into being on the Ubuntu desktop (down in the bottom right corner by default).

Having the recycle bin/trash can on the desktop will allow you to take advantage of Ubuntu 22.04’s new ‘arrange icons by type as Home/Drive/Trash’ option in the desktop right-click menu (some users are getting confused by the menu mentioning ‘trash’ when there’s no trash can on the desktop).

Читайте также:  Мониторинг температуры процессора linux mint

If you change your mind and want to remove the trash can from the Ubuntu 22.04 desktop run:

gsettings set org.gnome.shell.extensions.ding show-trash false

I should stress that don’t have to use the command line to do this task If you install the GNOME Extension Prefs tool you get access to the DING desktop extension’s full roster of settings via a GUI. However, in this instance I think the CLI is the quicker option.

Home / How To / How to Put the Trash Can on the Desktop in Ubuntu 22.04

Источник

A Trash-Bin for the Ubuntu Command Line

Ubuntu Commandline Trash-bin

Ubuntu Commandline Trash-bin

As a Linux user, you may need to delete files from your system from time to time. We tend to be cautious while deleting files, especially when deleting them permanently, as we do not want to mistakenly lose useful information forever. Unfortunately, there are instances when we delete something by mistake and there is no way to recover it. Or, it happens that we intend to delete only files from a folder but mistakenly delete files from the subfolders as well. In the graphical interface, things are pretty much visible and there is also the Trashcan utility to recover deleted files. However, file deletion is especially a sensitive operation in the Linux command line.

In this article, we will explain a few ways to safely remove files through the Ubuntu command line and also install a Trash CLI so that files can be recovered if we have deleted them by mistake.

We have run the commands and procedures mentioned in this article on an Ubuntu 22.04 LTS system.

Since we are using the Ubuntu command line application, the Terminal, you can open it either through the system Dash or the Ctrl+Alt+T shortcut.

The rm command – The brutal way of deletion

The rm command in Linux is used to remove files and folders from the system. Although it is the most widely used command for this purpose, it is not the optimal way to do so. It is because when you delete files and folders through this command, they are extremely hard to recover. Let us go through the syntax that we usually follow in order delete files and folders:

Delete a file with rm command

The following command will remove the specified file permanently from your system:

Delete Files in all folders and sub-folders

The following command will remove the specified folder, including its files and all the files in its subfolders permanently from your system:

Making safe deletion through the rm command

The above mentioned commands remove the files from the system almost permanently; so whats gone is pretty much gone. The system does not even prompt you for confirmation before deleting any file. How about use a switch that asks you for confirmation before deleting a file from your system?

Delete files by first getting a confirmation prompt

When you use the -i switch, you will get a confirmation prompt before the system deletes the file.

Читайте также:  Install full linux on android

$ rm -i [/file-location/file-name]

The system will only delete the file if you enter Y as the answer to the confirmation prompt.

Getting a confirmation prompt when deleting more than 3 files

When we want to delete multiple files at once, it becomes a little troublesome to be asked every time before the deletion of each file. The -I switch will only give you a confirmation prompt if you select to delete more than 3 files at once or you are deleting recursively in folders and sub-folders.

$ rm -I [/file-location/file-name]

The command line Trashcan – The recoverable way of deletion

The -i and -I switches mentioned above might be a careful way of deleting files but the safest route is to have an option to recover files even when you have deleted them. The Trash Can command line interface provides exactly what the Trash or Recycle bin does in the UI.

Installing the Trash CLI

Run the following command as root in your Terminal as only an authorized user can install software on Ubuntu:

$ sudo apt-get install trash-cli

Trash-cli installtion

You may be required to enter the password for sudo. Once the installation is complete, you can verify the installation and also check the version number of the trash utility through the following command:

The trash command can be used in multiple ways. You can view what can be done with it, through the various switches by checking the trash help through the following command:

The Ubuntu trash command

Using the Trash CLI

You can perform the following operations through the Trash CLI:

Delete a file by sending it to the Trash Can

Use the following command to send a file to the Trash can:

$ trash [/file-location/file-name]

List files in the Trash Can

Use the following command in order to list all the files currently residing in the Trash can:

Empty the Trash Can

Use the following command in order empty the Trash can; this will remove the files permanently from the system:

Restore Files from the Trash Can

Use one of the following commands in order to restore the files to the location from where they were deleted:

When you run this command, the Trash utility will list all the files from the Trash can with a unique number assigned to each. Enter the number against a file in order to restore it.

After reading this article, you are better equipped with safely deleting files through the Ubuntu command line. You can use the mentioned switches with the rm command to get a prompt before deletion or use the Trashcan CLI in order to perform all those operations that you could otherwise do with the graphical Ubuntu Trash utility.

About This Site

Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.

Latest Tutorials

Источник

Оцените статью
Adblock
detector