Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taking/47b15df678b033aa57cd06aff03a6787 to your computer and use it in GitHub Desktop.
Save taking/47b15df678b033aa57cd06aff03a6787 to your computer and use it in GitHub Desktop.
#!/bin/bash
# 이동할 디렉토리 설정
source_dir="/volume/500GB_HDD/Downloads"
# 파일 확인 및 이동 함수
move_files() {
for file in "$1"/*; do
if [ -d "$file" ]; then
# 디렉토리인 경우 재귀 호출
move_files "$file"
elif [ -f "$file" ]; then
# 파일인 경우 확장자 확인
extension="${file##*.}"
if [[ "$extension" == "mkv" || "$extension" == "mp4" ]]; then
# 이동할 디렉토리로 파일 이동
mv "$file" "$source_dir"
echo "Moved: $file"
fi
fi
done
}
# 크기가 100KB 미만인 폴더 삭제 함수
delete_small_directories() {
for dir in "$1"/*; do
if [ -d "$dir" ]; then
# 디렉토리인 경우 크기 확인
size=$(du -s "$dir" | awk '{print $1}')
if [ "$size" -lt 100 ]; then
# 크기가 100KB 미만인 디렉토리 삭제
rm -rf "$dir"
echo "Deleted directory: $dir"
else
# 크기가 100KB 이상인 경우 재귀 호출
delete_small_directories "$dir"
fi
fi
done
}
# 지정한 경로에서 시작하여 파일 이동 시작
move_files "$source_dir"
# 지정한 경로 내 100KB 미만인 디렉토리 삭제
delete_small_directories "$source_dir"
echo "이동 및 삭제가 완료되었습니다."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment