Recommanded Free YOUTUBE Lecture: <% selectedImage[1] %>

stat

파일의 정보를 읽어온다. 리턴값은 파일의 13가지 정보들이다. 파일이름 혹은 FILEHANDLE, DIRHANDLE 를 모두 사용할 수 있다. 실패할 경우 null 을 리턴한다. 아래와 같이 사용한다.
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
    $atime,$mtime,$ctime,$blksize,$blocks)
= stat($filename);
각 필드의 의미하는 바는 아래와 같다.
0 dev 파일시스템의 device 번호
1 ino inode 번호
2 mode 파일모드 (권한과 타입)
3 nlink 하드링크(:12)의 개수
4 uid 파일 소유자의 UID(:12)
5 gid 파일 소유자의 그룹 아이디
6 rdev device identifier
7 size 파일의 크기, byte(:12)
8 atime 최근 access 시간
9 mtime 최근 수정 시간
10 ctime 최근 변경된 시간
11 blksize 파일 시스템 의 block size
12 block 할당된 block 크기
Fcntl 모듈을 import 하면 모드 상수값과 S_IF*/S_IS* 함수를 사용해서 파일모드와 종류를 테스트 할 수 있다.

예제

#!/usr/bin/perl
use File::stat;
use Fcntl ':mode';

my $finfo;
$finfo = stat($ARGV[0]) || die("cannot open file : $ARGV[0]\n");

printf "File Name are %s\n", $ARGV[0];
printf "File Size are %d\n", $finfo->size;
printf "Permission are %04o\n", $finfo->mode & 07777;
printf "File Size are %d\n", $finfo->size;

if (S_IRGRP & $finfo->mode)
{
        printf("oK Group Read\n");
}
if (S_ISFIFO($finfo->mode))
{
        printf("FIFO File\n");
}