Skip to content

Instantly share code, notes, and snippets.

@kougazhang
Last active February 28, 2022 00:55
Show Gist options
  • Save kougazhang/31712b2588a77135bb190adb37fbb42f to your computer and use it in GitHub Desktop.
Save kougazhang/31712b2588a77135bb190adb37fbb42f to your computer and use it in GitHub Desktop.
#shell #delete #rsync
# 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
@kougazhang
Copy link
Author

for i in {1..12};do if [ $i -lt 10 ]; then i=0$i; fi; rm -rf /disk/sata$i/2019-03-26; done

@kougazhang
Copy link
Author

kougazhang commented Feb 23, 2022

#!/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