본질적으로 이 명령을 실행하고 싶습니다 ...
ln -s /opt/gitlab/embedded/service/gitlab-shell/hooks/ /var/opt/gitlab/git-data/repositories/web/*/hooks
이렇게 하면 후크라는 웹 폴더 아래의 모든 폴더에 심볼릭 링크가 생성되지만 오류는 반환되지 않지만 실제로 심볼릭 링크를 추가하지는 않습니다.
답변1
find
옵션 을 사용하여 명령을 사용하고 싶을 수도 있습니다 maxdepth
. 다음과 같은 샘플 디렉터리 구조를 만들었습니다.
/tmp/parent
/tmp/parent/subdir2
/tmp/parent/subdir1
/tmp/parent/subdir4
/tmp/parent/subdir4/notme
/tmp/parent/subdir3
/tmp/hooks
하위 디렉터리가 아닌 각 하위 디렉터리에 심볼릭 링크를 만들고 싶다고 가정해 보겠습니다 notme
.
root@xxxxxxvlp12 ~ $ find /tmp/parent -type d -maxdepth 1 -exec ln -s /tmp/hooks {} \;
root@xxxxxxvlp12 ~ $ find /tmp/parent -ls
2490378 4 drwxr-xr-x 6 root root 4096 Oct 7 12:39 /tmp/parent
2490382 4 drwxr-xr-x 2 root root 4096 Oct 7 12:39 /tmp/parent/subdir2
2490394 0 lrwxrwxrwx 1 root root 10 Oct 7 12:39 /tmp/parent/subdir2/hooks -> /tmp/hooks
2490379 4 drwxr-xr-x 2 root root 4096 Oct 7 12:39 /tmp/parent/subdir1
2490395 0 lrwxrwxrwx 1 root root 10 Oct 7 12:39 /tmp/parent/subdir1/hooks -> /tmp/hooks
2490389 4 drwxr-xr-x 3 root root 4096 Oct 7 12:39 /tmp/parent/subdir4
2490390 4 drwxr-xr-x 2 root root 4096 Oct 7 12:38 /tmp/parent/subdir4/notme
2490396 0 lrwxrwxrwx 1 root root 10 Oct 7 12:39 /tmp/parent/subdir4/hooks -> /tmp/hooks
2490387 4 drwxr-xr-x 2 root root 4096 Oct 7 12:39 /tmp/parent/subdir3
2490397 0 lrwxrwxrwx 1 root root 10 Oct 7 12:39 /tmp/parent/subdir3/hooks -> /tmp/hooks
2490391 0 lrwxrwxrwx 1 root root 10 Oct 7 12:39 /tmp/parent/hooks -> /tmp/hooks
답변2
find
특정 경로 아래의 모든 디렉터리의 컨텍스트에서 명령을 실행하는 데 사용할 수 있습니다.
다음 명령은 /var/opt/gitlab/git-data/repositories/web/
해당 디렉터리( -type d
) 아래의 모든 파일을 찾고 검사 중인 현재 디렉터리( 로 표시됨)에 상대적인 심볼릭 링크를 {}
만듭니다 -exec
.
따라서 다음 find
명령은 필요한 작업을 수행합니다.
find /var/opt/gitlab/git-data/repositories/web/ -type d -exec ln /opt/gitlab/embedded/service/gitlab-shell/hooks/ {}/hooks \;
답변3
ln
. cp
인수가 세 개 이상인 경우 마지막 인수는 디렉터리로 처리됩니다.
에서남자 ln:
ln [option]... target... directory
대신 for 루프를 사용해야 합니다.
답변4
주위를 둘러보고 find 명령을 사용해 본 후에는 ./*/
. 모든 도움에 감사드립니다! 나는 훨씬 더 세밀하게 조정된 스크립트를 내 github 계정에 만들었습니다. gitlab에만 해당되지만 필요한 내용을 수정하는 데 몇 분 밖에 걸리지 않습니다.https://github.com/michaeljs1990/bash-scripts/blob/master/gitlab-hooks-migration.sh.
#!/bin/bash
find . -name "hooks" -type l -delete
hooks="hooks"
for i in ./*/; do
ln -s /opt/gitlab/embedded/service/gitlab-shell/hooks/ $i$hooks
done