Operators and meanings of file tests in perl
Test file permissions:
-R files or directories are currently (valid) readable for users.
-W files or directories are writable to current (valid) users.
-X files or directories are executable to (valid) users currently.
-O files or directories are available to (valid) users currently.
-R files or directories are readable to actual users or groups.
-W files or directories can be written to actual users or groups.
-X files or directories can be executed by actual users or groups.
-O files or directories owned by actual users
The test file exists:
-E files or directories exist.
-Z file exists but no content
-S file or directory exists
Test file type:
-F is a common file.
-D is the Directory
-L is a symbolic link.
-S is a socket-type file.
-P is the named pipe.
-B is a block device file.
-C is a character device file.
-The setuid bit is set in the u file or directory.
-The setguid bit is set in the g file or directory.
-The sticky bit is set in the-k file or directory.
-T file handle is a TTY device
-T text file
-B: Binary File
Test file time:
-M: the number of days since the last modification
-A: the number of days since the last access
-C Number of days since the last file node was changed
The following perl program can check whether the files in a directory are readable and executable. The directory name is passed in by the command line.
#!/usr/bin/perl -wopendir(FH,"@ARGV[0]");my @list=readdir FH;closedir(FH)foreach my $file (@list){if (-r -w -x $file){print "$file is readable,writeable and excuteable\n"}}