Skip to content

Instantly share code, notes, and snippets.

@Nunocky
Created December 5, 2023 11:42
Show Gist options
  • Save Nunocky/a0ca08e2de6b984d653cd32d1eba2d80 to your computer and use it in GitHub Desktop.
Save Nunocky/a0ca08e2de6b984d653cd32d1eba2d80 to your computer and use it in GitHub Desktop.
構成をそのままにシンボリックリンクを張る
#!/bin/bash
SRC="../../src"
DEST="."
# 現在のディレクトリからシンボリックリンクを検索し、削除
find . -type l -exec rm {} +
# 現在のディレクトリからディレクトリを検索し、削除
# '.' と '..' を除外するために -mindepth 1 を使用
find . -mindepth 1 -type d -exec rm -rf {} +
echo "シンボリックリンクとディレクトリの削除が完了しました。"
# ディレクトリXが存在するか確認
if [ ! -d "$SRC" ]; then
echo "ソースディレクトリが存在しません: $SRC"
exit 1
fi
# ディレクトリYが存在しない場合は作成
mkdir -p "$DEST"
# ディレクトリX内のファイルに対してループ
find "$SRC" -type f | while read -r file; do
# ディレクトリ構造を保持するためのサブディレクトリを作成
subdir=$(dirname "$file" | sed "s|^$SRC|$DEST|")
mkdir -p "$subdir"
# シンボリックリンクを作成
ln -s "$file" "$subdir"
done
echo "シンボリックリンクの作成が完了しました。"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment