하드 링크는 일반 파일을 링크할 때 주로 이용하며, 옵션없이 ln 명령으로 링크시키면 된다. 생성된 링크 파일은 원래 파일의 inode(index node라 하며 파일에 대한 정보가 저장된 레코드)를 그대로 참조하기에 원 파일이 지워져도 아무런 문제가 되지 않는다.
[심볼릭 링크 - ln -s 명령으로 링크]
심볼릭 링크는 주로 디렉토리를 링크할 때 사용한다. 원 파일이 삭제되면 실제 데이터 블럭을 참조하던 inode도 삭제되어, 심볼릭 링크된 파일은 의미가 없어진다.
2. ln 명령어
[option]
-s : 심볼릭링크(소프트링크)를 생성한다. 만약 이 옵션이 없으면 하드링크가 생성된다.
-v : 링크를 만드는 정보를 자세히 출력한다.
[예제]
# ln -s /directory/* linkdir : /directory/디렉토리 안의 모든 파일의 링크 파일을 linkdir 디렉토리에 생성
# ln -s ./sourcefile ./linkfile : 링크생성
# ls -ld linkfile : 링크확인
# unlink(또는 rm) linkfile : 링크해제
/etc/xinetd.d 라는 디렉토리를 자주간다면 현재 나의 홈디렉토리에 링크해보자.
ln -s /etc/xinetd.d xx => /etc/xinetd.d라는 디렉토리를 현재 디렉토리의 xx라는 것으로 링크한다. ls xx 하면 ls /etc/xinetd.d의 내용과 동일한 내용이 나타나고 또한 cd xx하면 그 디렉토리안으로 들어간 것과 같다.
Usage: ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
or: ln [OPTION]... TARGET (2nd form)
or: ln [OPTION]... TARGET... DIRECTORY (3rd form)
or: ln [OPTION]... -t DIRECTORY TARGET... (4th form)
In the 1st form, create a link to TARGET with the name LINK_NAME.
In the 2nd form, create a link to TARGET in the current directory.
In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.
Create hard links by default, symbolic links with --symbolic.
When creating hard links, each TARGET must exist.
긴 옵션에서 꼭 필요한 인수는 짧은 옵션에도 꼭 필요합니다.
--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument
-d, -F, --directory allow the superuser to attempt to hard link
directories (note: will probably fail due to
system restrictions, even for the superuser)
-f, --force remove existing destination files
-n, --no-dereference treat destination that is a symlink to a
directory as if it were a normal file
-i, --interactive prompt whether to remove destinations
-s, --symbolic make symbolic links instead of hard links
-S, --suffix=SUFFIX override the usual backup suffix
-t, --target-directory=DIRECTORY specify the DIRECTORY in which to create
the links
-T, --no-target-directory treat LINK_NAME as a normal file
-v, --verbose print name of each file before linking
--help 이 도움말을 표시하고 끝냅니다
--version 버전 정보를 출력하고 끝냅니다
The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable. Here are the values:
none, off never make backups (even if --backup is given)
numbered, t make numbered backups
existing, nil numbered if numbered backups exist, simple otherwise
simple, never always make simple backups