Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Command Line Recycle Bin tool on Trash-Cli:Linux

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I'm sure everyone is familiar with the Recycle Bin (trashcan), because it's common for Linux users, Windows users, or Mac users. When you delete a file or directory, the file or directory is moved to the Recycle Bin.

It is important to note that when the file is moved to the Recycle Bin, the file system space is not released unless the Recycle Bin is emptied.

If you don't want to delete files permanently (empty the Recycle Bin), you can use the Recycle Bin to temporarily store deleted files, which can help us recover deleted files if necessary.

However, if you use the rm command to delete from the command line, it is impossible to find any deleted files or directories in the Recycle Bin. Therefore, be sure to think twice before executing the rm command. If you make a mistake (execute the rm command), the file is permanently deleted and cannot be recovered because the metadata stored on disk is gone.

According to the freedesktop.org specification, trash is a feature provided by desktop managers such as GNOME, KDE, and XFCE. When a file or directory is deleted through the file manager, the file or directory becomes trash and then moved to the Recycle Bin, which corresponds to $HOME/.local/share/Trash

The Recycle Bin directory contains two subdirectories: files and info. The files directory stores the files and directories that are actually deleted, and the info directory contains information about the deleted files and directories, such as the file path, date and time of deletion, and each file is stored separately.

You might ask, why do you need command-line tools when you already have a graphical user interface (GUI) recycle bin? Because for most guys who use the * NIX system (including me), even if they use a graphical user interface, they prefer to use the command line rather than the graphical user interface. So, if someone is looking for a command-line recycle bin tool, here's a good choice.

What is Trash-Cli?

Trash-cli is a command-line recycle bin tool and conforms to FreeDesktop.org 's trash specification. It can store the name, original path, deletion date and permissions of each junk file.

How to install Trash-Cli on Linux

Most official repositories of Linux distributions provide installation packages for Trash-Cli, so you can run the following commands to install them.

For Debian/Ubuntu users, use the apt-get or apt command to install Trash-Cli:

$sudo apt install trash-cli

For RHEL/CentOS users, use the yum command to install Trash-Cli:

$sudo yum install trash-cli

For Fedora users, use the dnf command to install Trash-Cli:

$sudo dnf install trash-cli

For Arch Linux users, use the pacman command to install Trash-Cli:

$sudo pacman-S trash-cli

For openSUSE users, use the zypper command to install Trash-Cli:

$sudo zypper in trash-cli

If you don't have an installation package for Trash-Cli in your distribution, you can also install it using pip. In order to be able to install python packages, you should have a pip package manager on your system.

$sudo pip install trash-cliCollecting trash-cliDownloading trash-cli-0.17.1.14.tar.gzInstalling collected packages: trash-cliRunning setup.py bdist_wheel for trash-cli... DoneSuccessfully installed trash-cli-0.17.1.14

How to use Trash-Cli

Trash-Cli is not difficult to use because it provides a very simple syntax. Trash-Cli provides the following commands:

Trash-put: delete files and directories (put in the Recycle Bin only) trash-list: list deleted files and directories trash-restore: restore files or directories from the Recycle Bin trash.trash-rm: delete files in the Recycle Bin trash-empty: empty the Recycle Bin

Next, let's try it with some examples.

1) Delete files and directories: in this example, we move the file 2g.txt and the folder magi to the Recycle Bin by running the following command.

$trash-put 2g.txt magi

It's the same as what you see in the file manager.

2) list deleted files and directories: in order to view deleted files and directories, you need to run the following command. After that, you can see the details of the deleted files and directories in the output, such as name, date and time of deletion, and file path.

$trash-list2017-10-01 01:40:50 / home/magi/magi/2g.txt2017-10-01 01:40:50 / home/magi/magi/magi

3) recover files or directories from the Recycle Bin: you can restore files and directories at any time by running the following command. It will ask you to select the file or directory you want to restore. In this example, I intend to restore the 2g.txt file, so my choice is 0.

$trash-restore0 2017-10-01 01:40:50 / home/magi/magi/2g.txt1 2017-10-01 01:40:50 / home/magi/magi/magiWhat file to restore [0.. 1]: 0

4) Delete files from the Recycle Bin: if you want to delete specific files in the Recycle Bin, you can run the following command. In this example, I will delete the magi directory.

$trash-rm magi

5) empty the Recycle Bin: if you want to delete all files and directories in the Recycle Bin, you can run the following command.

$trash-empty

6) delete junk files longer than X days: alternatively, you can delete files in the Recycle Bin that are longer than X days by running the following command. In this example, I will delete items that have been in the Recycle Bin for more than 10 days.

$trash-empty 10

Trash-Cli works well, but if you want to try some of its alternatives, you can also try gvfs-trash and autotrash.

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report