Created
May 5, 2026 11:06
-
-
Save Wxh16144/9e0bd5b04e71473620d46121db9b0bc4 to your computer and use it in GitHub Desktop.
iCloud 占用脚本 (iCloud Storage Filler)
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
| #!/bin/bash | |
| # Colors | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[0;33m' | |
| BLUE='\033[0;34m' | |
| RED='\033[0;31m' | |
| NC='\033[0m' # No Color | |
| # Log helpers | |
| log_info() { echo -e "${BLUE}$1${NC}"; } | |
| log_success() { echo -e "${GREEN}$1${NC}"; } | |
| log_warn() { echo -e "${YELLOW}$1${NC}"; } | |
| log_err() { echo -e "${RED}$1${NC}"; } | |
| # Define the target directory in iCloud Drive | |
| ICLOUD_DIR="$HOME/Library/Mobile Documents/com~apple~CloudDocs/iCloud_family_placeholder" | |
| FILENAME_PREFIX="tmpfile" | |
| # Help / Usage message | |
| show_usage() { | |
| log_info "Usage:" | |
| echo " ./fill_icloud.sh <size> <count> : Generate files (e.g., ./fill_icloud.sh 50m 2)" | |
| echo " ./fill_icloud.sh clean : Delete all generated placeholder files" | |
| echo "" | |
| log_warn "Size format: Use b, k, m, g (e.g., 500m, 1g)" | |
| } | |
| # Handle 'clean' command | |
| if [ "$1" == "clean" ]; then | |
| log_warn "Cleaning up generated files..." | |
| if [ -d "$ICLOUD_DIR" ]; then | |
| rm -f "$ICLOUD_DIR/${FILENAME_PREFIX}"_*.bin | |
| log_success "Cleanup complete." | |
| else | |
| log_err "Directory $ICLOUD_DIR does not exist. Nothing to clean." | |
| fi | |
| exit 0 | |
| fi | |
| # Check arguments | |
| if [ -z "$1" ] || [ -z "$2" ]; then | |
| show_usage | |
| exit 1 | |
| fi | |
| FILE_SIZE=$1 | |
| FILE_COUNT=$2 | |
| log_info "Preparing to generate $FILE_COUNT file(s) of size $FILE_SIZE..." | |
| # Create the directory if it doesn't exist | |
| mkdir -p "$ICLOUD_DIR" | |
| log_info "Target directory: $ICLOUD_DIR" | |
| for (( i=1; i<=$FILE_COUNT; i++ )) | |
| do | |
| FILE_PATH="$ICLOUD_DIR/${FILENAME_PREFIX}_${i}.bin" | |
| log_warn "Generating file $i : $FILE_PATH" | |
| # Using macOS native 'mkfile' | |
| mkfile -n "$FILE_SIZE" "$FILE_PATH" | |
| done | |
| log_success "Done! Files are now syncing to iCloud." |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
iCloud 占用脚本 (iCloud Storage Filler)
在 macOS iCloud Drive 中快速生成占位文件以占用空间的 Bash 脚本。
📦 下载
🚀 使用
chmod +x fill_icloud.sh./fill_icloud.sh 10g 5./fill_icloud.sh clean