Is there Recycle Bin in Ubuntu?

Restore the Trash can or Recycle bin icon if missing on your Ubuntu 22.04 LTS Jammy JellyFish Desktop using the command terminal.

In Windows, the deleted files go in to Recycle bin in case later you want o restore them. Similarly, we have a bin in Ubuntu Linux known as a Trash can. The purpose of it is also the same, whenever we delete some files, it moved to this Trash can.

Well, we are not comparing the Recycle bin and Trash can to each other instead we are here to know the command to restore the icon of it in Ubuntu 22.04.

On this Linux instead of on the Desktop, you will have the Trash can icon again on the Dock only. However all users won’t like it, some of us might want it again on the right-side bottom.

Well, there is an option in the Dock settings to show or hide the Trash can icon from the Dock but not for the Desktop.

Hence, if you are not finding an option to show the Trash can icon on Ubuntu Desktop, then here is the tutorial for that.

Contents hide

Show or Restore Trash can icon in Ubuntu 22.04

Open Command Terminal

Show the Trash icon on the Ubuntu desktop

Hide the Trash icon again

Automatically Delete Trash content

Automatically delete Temporary Files

Automatically Delete Period

How to restore Trash files in Ubuntu 22.04

Empty Trash

Show or Restore Trash can icon in Ubuntu 22.04

Open Command Terminal

To open the Terminal app on Ubuntu, you can visit the Applications and there search for it. Or else just type the shortcut command that is Ctrl+Alt+T.

Show the Trash icon on the Ubuntu desktop

Now, in your terminal run the given command. It will instantly restore or put back the Trash can icon on the right bottom side of your Ubuntu 22.04 LTS Linux.

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

Hide the Trash icon again

If after some time, you want to remove the Trash icon from the Ubuntu 22.04 Desktop, then run this command:

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

Let’s know a few more settings:

Automatically Delete Trash content

If you want your system to be cleaned the deleted files automatically after some time then we can enable an option called ” Automatically Delete Trash content“.

To get it, open the Trash can and click on the Settings button.

Is there Recycle Bin in Ubuntu?

After that, enable the Toggle button as shown in the following screenshot.

Automatically delete Temporary Files

Those who also want to delete the Temporary files gathered in their Ubuntu Linux can enable the Toggle button given for it.

Automatically Delete Period

Further, you can also set the time or days after which the Trash can must empty itself automatically. By default, it will be set for 30 days.

Is there Recycle Bin in Ubuntu?

How to restore Trash files in Ubuntu 22.04

Now, if you want some files from the Ubuntu Trash can back then open it, and find the file or folder that you want to restore. After that right click on that file to select Restore from Trash option. Whereas, if you want to delete it permanently then select Delete from Trash.

Is there Recycle Bin in Ubuntu?

Empty Trash

Well, if there is a scenario where you want to delete all the content of the Trash Can on Linux without going one by one to individual files. Then, simply right-click on the Trash can icon and select the option given for it.

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:

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

Example:

$ rm /home/textfile.txt

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:

$ rm -R [/folder-location]

Example:

$ rm -R /home/samplefolder

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.

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

Example:

$ rm -i /home/textfile.txt

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:

$ trash --version

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:

$ trash --version

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:

$ trash-list

Empty the Trash Can

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

$ trash-empty

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:

$ trash-restore

Or

$ rm -R /home/samplefolder
0

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.

Is there a recycle bin in Ubuntu Server?

The “Recycle Bin” in Windows and “Trash” in Ubuntu are both utilized to store deleted files and restore them at any time. While working in an Ubuntu, if you delete a file or directory from your system, the system moves that file to the trash folder.

Is there a recycle bin in Linux?

In older Linux versions, it used to be possible to retrieve the data, but nowadays, the metadata is wiped, and nothing is recoverable. The rm command doesn't have a recycle bin or a trash can. If we need a recycle bin, we should use the GUI, where files are usually moved to the trash directory when deleted.