Wednesday, November 26, 2008

Check file status in Perl

In Perl, here is a quick way to check file status.
if (-<para> $file)
where <para> is:
                    -r   File is readable by effective uid/gid.
                    -w   File is writable by effective uid/gid.
                    -x   File is executable by effective uid/gid.
                    -o   File is owned by effective uid.
                    -R   File is readable by real uid/gid.
                    -W   File is writable by real uid/gid.
                    -X   File is executable by real uid/gid.
                    -O   File is owned by real uid.
                    -e   File exists.
                    -z   File has zero size.
                    -s   File has non-zero size (returns size).
                    -f   File is a plain file.
                    -d   File is a directory.
                    -l   File is a symbolic link.
                    -p   File is a named pipe (FIFO).
                    -S   File is a socket.
                    -g   File has setgid bit set.
                    -k   File has sticky bit set.
                    -t   Filehandle is opened to a tty.
                    -T   File is a text file.
                    -B   File is a binary file (opposite of -T).
                    -M   Age of file in days when script started.
                    -A   Same for access time.
                    -C   Same for inode change time.
example 
my $myfile = "index.pl";
if (-e $myfile) { print " Yes File $myfile exists \n";}

So... using above tip how to find out the size of any given file?

No comments: