CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Fun With Perl: Perl Quizzes - Learn Perl the Fun Way:
Checking File Ownership & Permissions

 



sleuth
Enthusiast

Dec 13, 2000, 3:24 PM

Post #1 of 3 (28814 views)
Checking File Ownership & Permissions Can't Post

 
How do you check a file's ownership and permissions?

Slueth



sleuth
Enthusiast

Dec 15, 2000, 8:39 PM

Post #2 of 3 (28803 views)
Re: Checking File Ownership & Permissions [In reply to] Can't Post

 If anyone wants to know, you can use stat();

$filename = "file.db";
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($filename) or die "no $filename: $!";
print "Permission: $mode";

Also, going by the above variable names in the same order, they can be stored in an array for convenience.

@stats = stat($filename);
print "Permission: $stats[2]";

Sleuth



japhy
Enthusiast

Dec 15, 2000, 10:48 PM

Post #3 of 3 (28801 views)
Re: Checking File Ownership & Permissions [In reply to] Can't Post

You can also use the file test operators, for specific access:


Code
print "I can read $file\n" if -r $file; 
print "I can write to $file\n" if -w _;
print "I can execute $file\n" if -x _;

The _ is a special filehandle which refers to the previous one used ($file, in this case).

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives