Ubuntu8.04 the next script to replace rm

Source: Internet
Author: User
Ubuntu8.04 always brings me a lot of trouble, and this LSV is no exception. every two months, scim-launcher will load continuously until it is full of memory and swap. This time it is too late to run gnome-system-monitor (gnome-terminal is not to be mentioned, it is slower, it is too late ). Last time I created a new user yuanmm and login, backed up yuangg, copied the configuration file, and logged in to tune the font for half a day.

Ubuntu 8.04 always brings me a lot of trouble, and this LSV is no exception. every two months, scim-launcher will load continuously until it is full of memory and swap. It is too late to run gnome-system-monitor ). The last time I created a new user yuanmm and login, backed up yuangg, copied the configuration file, and logged in to tune the font for half a day. In case of protection, I also set the adjusted configuration file tar-vczf p2.tar.gz/home/yuanmm/. [a-zA-Z. It was used.

However, in the repeated chown/mv/cp/rm, accidentally deleted a. * folder that took a lot of time to collect. This is the second time. Last deleted *~ When the number of attacks is less ~, Who said CL is not prone to errors ?! The key is hard to recover ...... I decided to write a script to replace rm.

I used to think that shell programming is quite weak and difficult to read. I forgot everything when I learned high skills. As a result, I stayed up late last night and was late in the morning. I scanned the shell programming I had previously learned. I would like to share with you. Dos seems to have del commands, so my script is named del and placed in ~ /Sbin, and then

Chmod a + x ~ /Sbin/del, ln-s ~ /Sbin/*/usr/local/sbin.

#! /Bin/sh
If [! -D $ HOME/. trash]
Then mkdir $ HOME/. trash
Fi
If [$ LOGNAME = "root"]
# Then delBy = "$ LOGNAME @ $ USERNAME"
# Else delBy = "$ USERNAME"
Then delBy = ": $ USERNAME"
Fi

For toDel
Do
Backup = $ HOME/. trash/'basename $ toDel '$ delBy
Nsec = 'date + % N'
# Msec =$ {nsec: 0: 3}
If [! -F $ backup-! -D $ backup]
Then mv $ toDel $ backup
# Else mv $ toDel $ backup: $ msec
Else
Mv $ toDel $ backup: $ nsec
Touch-a $ backup: $ nsec
Fi
Done

I don't know why $ {nsec: 0: 3} cannot run normally. It can be used in command lines. Here, neither can 'echo $ {nsec: 0: 3. So I had to discard the msec timestamp. I want the final version to retain the information of the location to be deleted (for example, move tmp ~ /. Trash/tmp@home.yuangg: root @ yuangg: 616), and then write a udel to restore the deleted file. However, if the substring uses awk or sed, it will be out of the scope of the high operation. Wait for the idle time.

Related Article

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.