Delete files to the recycle bin by default in linux (implemented by bash)

Source: Internet
Author: User
In fedora, files are always accidentally deleted, so the following script moves the file deletion to its recycle bin by default. Function: The script deletes files or directories ~ /Waste/(defined by yourself ). The file name or directory name attached to the script is deleted by default and moved back...
In fedora, files are always accidentally deleted, so the following script moves the file deletion to its recycle bin by default. Function: The script deletes files or directories ~ /Waste/(defined by yourself ). If the script contains a file name or directory name, it means "delete" by default and is moved to the recycle bin. Parameter-l indicates listing the content of the recycle bin. If no parameter is provided, all content is listed. you can specify a file or directory. -D indicates that the recycle bin is cleared. if the parameter is left blank, you can delete a file or directory. The script execution permission is root. First, create a recycle bin www.2cto.com $ mkdir ~ with the root permission ~ /Waste is the script content [plain] #! /Bin/bash arg_del_flag = 0 # delete flag. the arg_list_flag = 0 # list flag is not deleted by default, by default, do not list Waste_Path = "/root/waste/" if [$ #-lt 1]; then echo "usage: $0-[l | d] [filename] "exit 1 fi file_num = 0 for param in $ @ do case $ param in"-d ") arg_del_flag = 1 # delete continue; "-l") arg_list_flag = 1 # list continue; "-" *) echo "unknow \" $ param \ "" echo "usage: $0-[l | d] [filename] "continue; *) file [$ file_num] =" $ param "# file name let File_num ++; esac www.2cto.com done I = 0 if [$ arg_del_flag-eq 1]; then cd $ {Waste_Path} if [$ #-eq 1]; then # Delete all rm-rf $ {Waste_Path} * exit 0 fi while [$ I-lt $ file_num] do if [-f $ {file [$ I]}]; then # for a common file rm-f $ {Waste_Path }$ {file [$ I]} elif [-d $ {file [$ I]}]; then # for the rm-rf $ {Waste_Path }$ {file [$ I]} else echo "$ {file [$ I]} is not existed" fi let I ++ done exit 0 fi if [$ arg_list_flag -Eq 1]; then cd $ {Waste_Path} if [$ #-eq 1]; then # list all ls-l $ {Waste_Path} exit 0 fi www.2cto.com while [$ I-lt $ file_num] do if [-s $ {file [$ I]}]; then # whether the object exists-s indicates that the object has a stolen length greater than 0, return ls-l $ {Waste_Path }$ {file [$ I]} else echo "$ {file [$ I]} is not existed" fi let I ++ done exit 0 fi # The-l or-d option does not exist, delete the file while [$ I-lt $ file_num] do if [-f $ {file [$ I]}-o-d $ {file [$ I]}]; then # ensure that the file has a mv $ {file [$ I] }$ {Waste_Path} if [$? = 0]; then echo "$ {file [$ I]} deleted successfully" fi else echo "$ {file [$ I]} is not existed" fi www.2cto.com let I ++ done exit 0 modify the script execution permission, then add it to the system environment variable! The above script also has a small bug, that is, when I enter the recycle bin to determine whether a file exists, I use the-s option. if the file exists and the length is greater than 0, a success is returned. I lost the empty file to the recycle bin when I wrote the script test yesterday. all of the files have been closed for a long time. Hope you can give me more advice! From firefoxbug's column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.