A shell command for safely deleting files

Source: Internet
Author: User

A shell command for safely deleting files the functions in the following script can be safely used to delete xxxx. This command will move the xxx file (or directory (do not add/after directory ~ /Backup, and add a Time Label at the same time. By running delete_old ~ The oldest file or directory under the/backup directory that exceeds MB is deleted, and data protection is still useful # Description: This function used to move some useless files in current folder ~ /Backup/# Author: fulinux # Version: 1.0.0 (Release by fulinux on 8th limit L. 2013) function delete () {if [-z $1]; then echo "delete it to backuo directory" echo "Usage: $ FUNCNAME [express]" echo "Example: $ FUNCNAME fulinux/"return; fi express = $1 timestamp = $ (date + % Y % m % d % H % M % S) rechristen = $1. $ timestamp mv "$ express "~ /Backup/"$ rechristen"} # Description: This function used to search dir to fetch the oldest file # Author: fulinux # Version: 1.0.0 (Release by fulinux on 8th limit L. 2013) searchdir () {oldestfile = 'LS-rt | head-n 1 | awk' {print $1} ''} # Description: this function used to remove oldest useless files in ~ /Backup folder if its size is more than 4000 M # Author: fulinux # Version: 1.0.0 (Release by fulinux on 8th limit L. (2013) # This is the directory where backup files are keptbackup = ~ /Backup # maximum useless filesalarmrate = 3000 function delete_old () {cd $ backup while true; do backup_size = 'du-ms $ backup | awk '{print $1} ''if [$ backup_size-gt $ alarmrate]; then searchdir delete $ oldestfile else break; fi done}

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.