#!/usr/bin/perl # # get information about a file # # define source file parameter which is a link $source_file = "/temp/test/source/dir1/hello1_link.txt"; # define filetype array with potential first bits of mode @ftypes = qw(. p c ? d ? b ? - ? l ? s ? ? ?); $ftypes0 = ''; # Get File Statistics Using Scalar context ($dev,$inode,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($source_file); $perms = $mode & 07777; $octperms = sprintf("%lo", $perms); $filetype = $ftypes[($mode & 0170000)>>12]; # Try to Id a link using lstat $stat = lstat($source_file); octperms = sprintf("%lo", $perms); $filetype = $ftypes[($mode & 0170000)>>12]; # Try to Id a link using lstat $stat = lstat($source_file); if ( -l _) { print ("link identified using -l _ and lstat\n"); $link = "Y"; } # Try to Id a link with explicit -l test operator if ( -l $source_file) { print ("link identified using -l test operator \n"); $link = "Y"; } print ("source_file = $source_file \n"); print ("uid = $uid \n"); print ("gid = $gid \n"); print ("mode = $mode \n"); print ("perms = $perms \n"); print ("octperms = $octperms \n"); print ("filetype = $filetype \n"); print ("link = $link \n"); print ("nlink = $nlink \n"); link identified using -l _ and lstat link identified using -l test operator source_file = /temp/test/source/dir1/hello1_link.txt uid = 14442 gid = 554 mode = 164349 perms = 509 octperms = 775 filetype = - link = Y nlink = 1