###############################################################################
#
Name : Mahavairocana
#
Author : Mahavairocana
#
QQ : 10353512
#
WeChat : shenlan-qianlan
#
Blog : http://www.cnblogs.com/Mahavairocana/
#
Description : You are welcome to reprint, or hyperlinks to indicate the
#
source of the article, as well as author
information.
###############################################################################
#!/bin/sh #********************************************************************************** # * this tool is used for file size more than 1G, to make delete file smoothly # * truncate chunk size is 1G # * # * USAGE: ./rmbigfile.sh file_name sleep_seconds # * #*********************************************************************************** if [ $# != 2 ] ; then echo "" ; echo "/**********************************************************************************"; echo " * this tool is used for file size more than 1G, to make delete file smoothly"; echo " * truncate chunk size is 1G"; echo "/**********************************************************************************"; echo "" ; echo "USAGE: $0 file_name sleep_seconds" ; echo "" ; exit; fi FILE_NAME=$1; SLEEP_SECONDS=$2; date "+%Y-%m-%d %H:%M:%S"; echo "start..."; FILE_SIZE=`ls -s $FILE_NAME | awk '{print $1}'`; FILE_SIZE_G=`expr $FILE_SIZE / 1000000`; if [ $FILE_SIZE_G == 0 ] ; then echo "$FILE_NAME is less than 1G"; FILE_SIZE_G=1; else echo "$FILE_NAME is $FILE_SIZE_G G"; fi echo "prepare to truncate file: $FILE_NAME (${FILE_SIZE_G}G)"; echo "truncate chunk size is 1G, looping every $SLEEP_SECONDS second"; for i in `seq $FILE_SIZE_G -1 1 ` ; do sleep $SLEEP_SECONDS; cmd="truncate -s ${i}G $FILE_NAME"; echo "*** $cmd"; `$cmd`; done FILE_SIZE=`ls -s $FILE_NAME | awk '{print $1}'`; FILE_SIZE_G=`expr $FILE_SIZE / 1000000`; if [ $FILE_SIZE_G -le 1 ] ; then rm $FILE_NAME; fi echo "complete." date "+%Y-%m-%d %H:%M:%S"