The trash folder in Linux can be deleted; trash is the recycle bin file under Linux, which is used to store documents and materials temporarily deleted by users. The recycle bin file is a special folder. By pointing the rm command to the asterisk (*), you can delete all files and folders in the Trash folder.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
If you want to use the graphical interface to delete files on your computer, you may directly drag the files or folders to the "Trash" or "Recycle" stand". Alternatively you can select the file or folder you want to delete, right-click and select Delete.
There is no trash can when deleting files or folders in the terminal (at least not by default). On the graphical desktop, the Trash (trash folder) is a protected directory. The protection mechanism prevents users from accidentally deleting the directory or moving it from its default location so that it cannot be found. Trash is essentially nothing more than a highly managed folder, so you can create your own Trash folder for use in the terminal.
Set a trash bin for the terminal
Create a directory named Trash in the home directory:
$ mkdir ~/Trash
Delete files
When you want to delete a file or folder, use the mv command to move the file or folder to Trash:
$ mv example.txt ~/Trash
Permanently delete the file or folder
When you are ready to permanently delete a file or folder from the system, you can use the rm command to clear all data in the trash folder. By pointing the rm command at an asterisk (*), you can delete all files and folders within the Trash folder without deleting the Trash folder itself. Because users can create directories conveniently and freely, even if you accidentally delete the Trash folder, you can create a new one again.
$ rm --recursive ~/Trash/*
Usage of trash
Direct use is to execute the above instructions. For example, if you want to move the 123.txt file to the trash bin, just execute "trash-put 123.txt". After executing the trash command, the file is moved to the user's recycle bin. The path of each user's recycle bin is $HOME/.local/share/Trash. For example, user shuozhuo's recycle bin is located at /home/shuozhuo/.local/share/Trash, and user root's recycle bin is located at /root/.local/share/Trash.
The trash command is rm
For the convenience of use, here is the trash alias to rm command. Add the following statement in /root/.bashrc:
alias rm='trash-put' #rm指令默认就是将文件移动到回收站 root/.local/share/Trash/files alias rl='trash-list' #rl指令显示回收站的列表
Note: As for emptying the recycle bin, just use the original trash command
Then execute "source ~/.bashrc " to use The settings take effect.
Recommended learning:Linux video tutorial
The above is the detailed content of Can the trash folder be deleted in Linux?. For more information, please follow other related articles on the PHP Chinese website!