리눅스

chapter03 파일과 디렉토리 (05)

정지홍 2023. 3. 5. 20:12

링크

-기존 파일이나 디렉토리에 접근할 수 있는 새로운 이름

-복잡한 파일명을 간단한 다른 이름으로 접근 가능

 

 


하드 링크

-기존 파일과 동일한 inode 사용

 

#include <unistd.h>

int link(const char *existing 기존 파일 경로, const char *new 새로 생성할 링크의 경로)

 

link 함수 사용 예제


심볼릭 링크

-기존 파일에 접근 할 수 있는 다른 파일을 만들며 다른 inode사용

 

#include <unistd.h>

int symlink(const char *name1 기존 파일의 경로, const char *name2새로 생성할 파일 경로)

심볼링 링크 생성 예제


심볼릭 링크의 정보 검색

#include <sys/types.h>
#include <sys/stat.h>

int lstat(const char *path심볼릭 링크의 경로 , struct stat *buf검색한 파일 정보를 저장할 구조체 주소)


심볼릭 링크의 내용 읽기

#include <unistd.h>

ssize_t readlink(const char *restrict path 심볼링 링크 경로, char *restrict buf 읽어온 내용을 저장할 버퍼, size_t bufsize버퍼의 크기)

 


원본 파일의 경로 읽기

#include <stdlib.h>

char *realpath(const char *restrict file_name 심볼릭 링크 이름, char *restrict resolved_name경로명을 저장할 버퍼 주소);