Perl file Testing

Source: Internet
Author: User

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"}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.