성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>Windows - Symbolic (hard/soft) Link 및 Junction 차이점</h1> <p> 윈도우에 내장한 <a target='tab' href='https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mklink'>mklink</a>를 이용하면 특정 디렉터리에 대한 Symbolic Link 및 Junction을 연결할 수 있습니다.<br /> <br /> 예를 들어 볼까요? ^^ 우선 기존에 사용하던 디렉터리를 가정해 "C:\temp\testdir1"을 만듭니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\temp> <span style='color: blue; font-weight: bold'>mkdir testdir1</span> // 실습을 위해 임의 파일도 하나 만듭니다. c:\temp>echo "TEST" > c:\temp\testdir1\test.txt </pre> <br /> 이제 우리가 원하는 것은 해당 디렉터리에 대해 "C:\temp\testdir2"라는 새로운 이름을 만들어 연결하는 것입니다. (<a target='tab' href='https://www.sysnet.pe.kr/2/0/12221'>이때 "C:\temp\testdir2" 경로는 존재하지 않아야 합니다.</a>)<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\temp> <span style='color: blue; font-weight: bold'>mklink /J "testdir2" "testdir1"</span> c:\temp> <span style='color: blue; font-weight: bold'>dir</span> Volume in drive C has no label. Volume Serial Number is 015B-B1A4 Directory of c:\temp 2024-02-17 오후 02:38 <DIR> . 2024-02-17 오후 02:31 <DIR> testdir1 2024-02-17 오후 02:35 <span style='color: blue; font-weight: bold'><JUNCTION></span> testdir2 [c:\temp\testdir1] 0 File(s) 0 bytes 3 Dir(s) 340,979,662,848 bytes free </pre> <br /> 보는 바와 같이 새롭게 명명한 "testdir2"로 "JUCTION" 항목이 하나 추가되고, 탐색기에서 살펴보면 "폴더" 아이콘에 "화살표"가 하나 추가된 것으로 그것이 JUNCTION임을 알 수 있습니다.<br /> <br /> <img alt='junction_dir_1.png' src='/SysWebRes/bbs/junction_dir_1.png' /><br /> <br /> 이후부터는 testdir2 경로를 마치 testdir1을 다루듯이 사용할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // testdir2의 파일을 나열하도록 명령하면 그것과 연결된 testdir1의 파일을 나열 c:\temp> <span style='color: blue; font-weight: bold'>dir .\testdir2 /b</span> test.txt </pre> <br /> 그렇다면 삭제는 어떻게 할까요? 왠지 걱정이 드는 것은, 저렇게 연결되었다는 점에서 혹시 testdir2를 삭제하면 원본인 testdir1도 통째로 날아가는 것은 아닐까요? ^^<br /> <br /> 재미있게도, 삭제만큼은 연결 기능을 하지 않아 그냥 안전하게 rd 명령어로 제거할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // testdir2 junction만 삭제 c:\temp> <span style='color: blue; font-weight: bold'>rd testdir2</span> // 기존에 연결되었던 디렉터리는 그대로 존재 c:\temp> <span style='color: blue; font-weight: bold'>dir /b</span> testdir1 </pre> <br /> 물론, rd 명령어가 아닌 "윈도우 탐색기"에서 해당 항목을 삭제해도 됩니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> Junction에 대해 봤으니, 이제 mklink의 "/D" 옵션으로 연결할 수 있는 symbolic link에 대해서도 살펴보겠습니다. 일례로, C:\Users 디렉터리에서 dir /a 명령을 내려보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\Users> <span style='color: blue; font-weight: bold'>dir /a</span> Volume in drive C has no label. Volume Serial Number is 015B-B1A4 Directory of c:\Users 2024-02-17 오후 11:18 <DIR> . 2024-02-17 오후 11:28 <DIR> .. 2022-05-07 오후 02:41 <span style='color: blue; font-weight: bold'><SYMLINKD></span> All Users [C:\ProgramData] 2022-09-27 오후 06:48 <DIR> Default 2022-05-07 오후 02:41 <JUNCTION> Default User [C:\Users\Default] ...[생략]... </pre> <br /> Junction 외에도 SYMLINKD로 표시되는 항목이 있습니다. 윈도우 탐색기에서는 아이콘이 동일하므로 구분이 안 되는데요, 대신 속성창을 띄워보면 Symolic Link의 경우에는 "Shortcut" 탭이 하나 더 있는 걸로 알아낼 수는 있습니다.<br /> <br /> 기본적인 수준에서의 동작은 Junction과 (삭제까지도) 다른 점이 없습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 그런데, 도대체 그 둘 간의 차이가 뭘까요? 이에 대해 검색해 보면 다음의 글을 찾을 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Pete Hinchley: Junctions and Symbolic Links ; <a target='tab' href='https://hinchley.net/articles/junctions-and-symbolic-links'>https://hinchley.net/articles/junctions-and-symbolic-links</a> </pre> <br /> 가장 뚜렷한 기능상의 차이점은, Junction은 로컬 PC 내에서만 연결을 할 수 있는 반면 Symbolic Link는 원격으로 연결도 가능하다고 합니다. 또한, 연결 결과가 대상에서 이뤄지느냐 로컬에서 이뤄지느냐로 나뉩니다.<br /> <br /> 가령, 다음과 같이 Junction으로 연결된 상태인 경우,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > mklink /J c:\alias c:\target </pre> <br /> 만약 원격에서 위와 같이 Junction으로 연결된 "\\remote\c<span class="tex2jax_ignore">$</span>\alias"로 요청을 하면 자동으로 "\\remote\c<span class="tex2jax_ignore">$</span>\target"에 대한 결과로 이어집니다. 하지만, 만약 Symbolic Link로 연결했다면, <br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > mklink /D c:\alias c:\target </pre> <br /> 원격에서 "\\remote\c<span class="tex2jax_ignore">$</span>\alias"로 요청을 한 경우, 서버는 "c:\target" 정보를 클라이언트에 보내게 되고, 결국 (서버 측의 "\\remote\c<span class="tex2jax_ignore">$</span>\target"이 아닌) 요청한 측의 "c:\target" 디렉터리를 접근하려고 시도하게 됩니다. <br /> <br /> 참고로, Junction은 (Windows 2000부터 적용한) NTFS 3.0부터 지원한다고 합니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 마지막으로, Symbolic Link는 유형에 따라 "hard-link"와 "soft-link"로 나뉘는데, hard-link는 원본에 참조 카운트를 유지하는 방법으로 구현하기 때문에 실제 파일을 삭제하려면 원본 및 hard-link를 모두 삭제해야 한다는 특징이 있습니다. 반면, soft-link (및 junction)은 일종의 shortcut처럼 동작하기 때문에 원본을 삭제하면 soft-link와 junction은 더 이상 가리킬 곳이 없는 상태로 존재만 하게 됩니다. 이 외에도 hard-link는 다음과 같은 차이점을 가지고 있습니다.<br /> <br /> <ul> <li>오직 파일 연결만 가능하고,</li> <li>연결 대상의 파일이 hard-link를 생성하는 시점에 반드시 존재해야 하고,</li> <li>같은 볼륨 내에서만 생성 가능 (즉, C:\ 드라이브의 파일을 D:\ 드라이브에서 연결할 수 없음)</li> </ul> <br /> 그리고 Symbolic link의 연결은 fsutil을 이용해 제어하는 것이 가능합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\Windows\System32> <span style='color: blue; font-weight: bold'>fsutil behavior set symlinkevaluation /?</span> Usage: fsutil behavior set symlinkEvaluation {L2L|L2R|R2L|R2R}:{0|1} [...] Controls the class of symbolic links that can be traversed when opening files. Values: L2L:{0|1} - Controls local-to-local symbolic link evaluation (default ENABLED) L2R:{0|1} - Controls local-to-remote symbolic link evaluation (default ENABLED) R2L:{0|1} - Controls remote-to-local symbolic link evaluation (default DISABLED) R2R:{0|1} - Controls remote-to-remote symbolic link evaluation (default DISABLED) Eg: fsutil behavior set symlinkEvaluation L2L:1 L2R:0 - Enables local-to-local symbolic link evaluation - Disables local-to-remote symbolic link evaluation - Does not change the evaluation state of remote-to-remote or remote-to-local links. This operation takes effect immediately (no reboot required) </pre> <br /> 보는 바와 같이, Local 내에서의 연결과 Local에서 Remote로의 연결은 기본적으로 활성화돼 있어 fsutil로 변경할 필요 없이 곧바로 생성할 수 있습니다.<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1961
(왼쪽의 숫자를 입력해야 합니다.)