指定したフォルダ内の全てのディレクトリに .gitkeep
ファイルを作成する方法
create_gitkeep.sh
#!/bin/bash
# 引数が指定されているかチェック
if [ -z "$1" ]; then
echo "使用方法: $0 <ターゲットフォルダのパス>"
exit 1
fi
# 引数として指定されたフォルダ
TARGET_DIR="$1"
# 再帰的にサブディレクトリに移動して .gitkeep ファイルを作成
find "$TARGET_DIR" -type d -exec sh -c 'cd "{}" && touch .gitkeep' \;
echo "再帰的に .gitkeep ファイルを作成しました。"
実行権限を付与
chmod 700 create_gitkeep.sh
実行
./create_gitkeep.sh /path/to/folder
これにより、指定したフォルダ内の全てのディレクトリに .gitkeep
ファイルが作成されます。