Replace RM command to prevent accidental deletion

Source: Internet
Author: User

  1. To place the accidental deletion script:

    /usr/bin/remove.sh

  2. #!/bin/bashpath_cnt= "$#" trash_dir= "$HOME/.trash" mkdir -p  $TRASH _dirmenu () {echoecho -e  "\t\ t\tsys options menu\n "echo -e " \t1. delete ok! " echo -e  "\t2. Don ' t delete, into the recycle bin:  $HOME/.trash "echo -e " \t0. exit menu\n\n "echo -en " \t\tenter options:   "read -n 1 option} Mvfunc () {for i in [email protected]dostamp= ' date +%y%m%d%h%m%s ' fileName= ' basename   $i ' mv -f  $i   $TRASH _dir/$fileName. $STAMP  echo done}rmfunc () {for i in  [email protected]dostamp= ' date +%y%m%d%h%m%s ' filename= ' basename  $i ' [ -n  $i  ] &&  rm -rf  $i   $TRASH _dir/$fileName. $STAMP  echo done} while :d omenucase  $option  in "1") rmfunc [email protected] && exit  0;; " 2 ") mvfunc [email protected] && exit 0 ;; " 0 ") break;; *) echo  "sorry,wrong selection";; Esacdone

3. Modify ~/.bash_profile (personal preference file), if you want any user to modify, add global profile in/etc/profile.d/:

such as/etc/profile.d/remove.sh

Alias rm= ' sh/usr/bin/remove.sh '

It will start when the user logs in or generates a new process.


4. Regular cleaning of litter bins

such as the use of crontab mechanism, such as 0 0 * * * rm-rf/home/username/.trash/*

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/83/09/wKioL1dpDDay91c4AAANfOrphGI754.png-wh_500x0-wm_3 -wmp_4-s_1902965991.png "title=" Qq20160621174257.png "alt=" Wkiol1dpdday91c4aaanforphgi754.png-wh_50 "/>

5. Implementation results

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/83/0A/wKiom1dpDJCBxbLHAAAX_SwUKqY468.png-wh_500x0-wm_3 -wmp_4-s_1619329970.png "title=" Qq20160621174424.png "alt=" Wkiom1dpdjcbxblhaaax_swukqy468.png-wh_50 "/>

test.py.2016062117521466502755


This article is from the "zcy.gy" blog, make sure to keep this source http://1064187464.blog.51cto.com/9108437/1791469

Replace RM command to prevent accidental deletion

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.