파일(file)
- 보조기억장치의 의미있는 정보의 집합
- 구성 요소
- 이름
- 실행하기 위한 정보
- 부가 정보(메타 데이터/속성)
파일 속성 다루기
$ stat -c 'blocks: %b, filename: %n' filename blocks: 32, filename: filename
- 유형(확장자)
- 크기
- 생성 날짜
- 마지막 접근 날짜
- 마지막 수정 날짜
- 생성자
- 소유자
- 위치
파일(+디렉터리) 접근 단위: 블록(block)
struct stat {
dev_t st_dev; //파일이 있는 장치 ID
ino_t st_ino; //i-node 번호
mode_t st_mode; //파일 타입, 모드 및 퍼미션
nlink_t st_nlink; //하드 링크 수
uid_t st_uid; //소유자의 유저 ID
gid_t st_gid; //소유자의 그룹 ID
dev_t st_rdev; //특수 파일일 경우 장치 ID
off_t st_size; //파일 크기(바이트 단위)
blksize_t st_blksize; //블록 크기
blkcnt_t st_blocks; //할당된 블록 수
struct timespec st_atim; //최근 접근 시간
struct timespec st_mtim; //최근 수정 시간
struct timespec st_ctim; //최근 상태 변경 시간
};
stat
int stat(const char *filename, struct stat *buf);
- Parameter
- filename:파일 경로
- buf: stat 정보를 저장할 버퍼
- Return
fstat
int fstat(int filedes, struct stat *buf);
- Parameter
- filedes:파일 디스크립터
- buf: stat 정보를 저장할 정보
- Return