Last active
February 28, 2022 00:55
-
-
Save kougazhang/31712b2588a77135bb190adb37fbb42f to your computer and use it in GitHub Desktop.
#shell #delete #rsync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# clean the same relative path in echo disk. the disk name like /disk/sata01, /disk/sata02 | |
for i in {1..12};do | |
if [ $i -lt 10 ]; then | |
i=0$i | |
fi | |
rm -rf /disk/sata$i/<filepath> | |
done |
#!/usr/bin/env bash
mkdir -p /disk/ssd1/empty
# filter SATA HDD
all=(`df -h|grep /disk/sata|awk '{print $NF}'`)
for i in "${all[@]}"
do
echo "$i"
ls $i|grep -v hdfs| xargs -n1 -I{} rsync --delete-before -av /disk/ssd1/empty/ $i/{}/ > /dev/null
done
易错点:
/disk/ssd1/empty/ 和 /disk/sata$i/{}/ 的后缀不能忘记。
rm删除内容时,将目录的每一个条目逐个删除(unlink),需要循环重复操作很多次;rsync删除内容时,建立好新的空目录,替换掉老目录,基本没开销。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for i in {1..12};do if [ $i -lt 10 ]; then i=0$i; fi; rm -rf /disk/sata$i/2019-03-26; done