一、构建测试文件
1、构造文件和文件夹
#! /bin/bash
path="/home/parasaga/testtmp"
if [ ! -d path ];
then
mkdir -p $path
fi
for index in {1..500000}
do
echo $index
num=`expr $index / 1000`
num1=$(( $index % 100 ))
tmpPath="${path}/data_${num}/data_${num1}"
echo $tmpPath
if [ ! -d $tmpPath ];
then
mkdir -p $tmpPath
fi
echo "${index}" > $tmpPath/bk-${index}.txt
done
2、只构造文件
path="/home/parasaga/testtmp"
if [ ! -d path ];
then
mkdir -p $path
fi
for index in {1..10}
do
echo $index > /home/parasaga/testtmp/$index.txt
done
二、测试删除
1、方法一:使用rm命令
path="/home/parasaga/testtmp"
start_time=$(date +%s)
rm -rf $path
end_time=$(date +%s)
cost_time=$[ $end_time-$start_time ]
echo "清空文件共消耗:$(($cost_time/60))min $(($cost_time%60))s"
2、方法二:使用rsync命令
blankPath="/home/parasaga/blank/"
deletePath="/home/data/log/"
if [ ! -d "$blankPath" ]; then
mkdir $blankPath
fi
start_time=$(date +%s)
rsync --delete-before -a -H -v --progress --stats $blankPath $deletePath
end_time=$(date +%s)
cost_time=$[ $end_time-$start_time ]
echo "清空文件共消耗:$(($cost_time/60))min $(($cost_time%60))s"
3、方法三:使用find with delete命令
deletePath="/home/data/log/"
find $deletePath -type f -delete
|