본문 바로가기
CS/Linux

파일 관리 관련 함수

by JHyun0302 2023. 8. 29.
728x90

umask(2) : 새로운 파일 생성 시 접근권한(mask) 설정

mode_t umask(mode_t mask);
  • 1번 파라미터 : 설정되지 않아야 할 접근 권한

 

 

access(2) : 접근 권한이 있는지 확인 및 파일 존재 여부 확인

int access(const char* pathname, int mode);
  • 1번 파라미터 : 파일 경로
  • 2번 파라미터 : 접근 권한 확인

 

매크로 상수 의미
R_OK 읽기 권한 검사
W_OK 쓰기 권한 검사
X_OK 실행 권한 검사
F_OK 파일 존재 여부 검사

 

 

 

chmod(2), fchomd(2) : 파일 접근 권한 변경

int chmod(const char* pathname, mode_t mode); 
int fchmod(int fd, mode_t mode);

※ chmod(2)

  • 1번 파라미터 : 파일 경로
  • 2번 파라미터 : 새로운 접근 권한 (8진수)

※ fchmod(2)

  • 1번 파라미터 : 파일 디스크립터
  • 2번 파라미터 : 새로운 접근 권한 (8진수)

 

 

chown(2), fchown(2) : 파일 소유자, 소유그룹 변경

int chown(const char* pathname, uid_t owner, gid_t group); 
int fchown(int fd, uid_t owner, gid_t group);

※ chown(2)

  • 1번 파라미터 : 파일 경로
  • 2번 파라미터 : 새로운 소유자 id 
  • 3번 파라미터 : 새로운 소유 그룹 id

※ fchown(2)

  • 1번 파라미터 : 파일 디스크립터
  • 2번 파라미터 : 새로운 소유자 id 
  • 3번 파라미터 : 새로운 소유 그룹 id

 

 

 

link(2): hard link 생성 (원본 파일의 별칭 생성)

int link(const char* oldpath, const char* newpath);
  • 1번 파라미터 : 원본 파일 경로
  • 2번 파라미터 : 하드 링크 경로

 

ln test.txt test_hardLink.txt //test.txt 하드링크 생성

 

 

 

 

 

 symlink(2) : symbolic link 생성 (원본 파일 가리킴 = 윈도우의 바로가기)

int symlink(const char* target, const char* linkpath);
  • 1번 파라미터 : 원본 파일 경로
  • 2번 파라미터 : 소프트 링크 경로

 

ln -sf test.txt testSymbolic.txt //test.txt 심볼릭 링크 생성

 

 

 

readlink(2) : soft link로부터 원본 파일 경로 읽기

ssize_t readlink(const char* pathname, char* buf, size_t bufsiz);
  • 1번 파라미터 : 소프트 링크 경로
  • 2번 파라미터 : 원본 파일 경로 담을 버퍼
  • 3번 파라미터 : 버퍼 크

 

 

 

unlink(2) : 파일 삭제하지만 디렉토리 삭제 불가

int unlink(const char* pathname);
  • 1번 파라미터 : 삭제할 파일 경로

 

 

 

remove(3) : 파일 or 빈 디렉토리 삭제

int remove(const char* pathname);
  • 1번 파라미터 : 삭제할 파일 경로

 

 

rename(2) : 파일 위치와 이름 변경

int rename(const char* oldpath, const char* newpath);
  • 1번 파라미터 : 이동 할 파일 경로
  • 2번 파라미터 : 새로운 파일 경로

 

 

stat(2), fstat(2) : 아이노드 블록의 파일 속성 가져옴

int stat(const char* pathname, struct stat* statbuf);
int fstat(int fd, struct stat* statbuf);

※ stat(2)

  • 1번 파라미터 : 파일 경로
  • 2번 파라미터 : 파일 속성 담을 버퍼

 

※ fstat(2)

  • 1번 파라미터 : 파일 디스크립터
  • 2번 파라미터 : 파일 속성 담을 버퍼

 

 

 

 

 

반응형

'CS > Linux' 카테고리의 다른 글

Process & Signal  (0) 2023.08.29
디렉토리 관리 관련 함수  (0) 2023.08.29
Func (File System & File Input/Output)  (0) 2023.08.29
텍스트 에디터(vi)  (0) 2023.08.28
리눅스 구조 & 명령어  (0) 2023.08.27