1. Perl
  2. builtin functions
  3. here

chmod function - change file permissions

Use the chmod function to change file permissions .

chmod 0666, $file;

To change the permissions, use the chmod function. The first argument specifies permissions in octal. To represent an octal number in Perl, prefix the number with 0.

The second argument specifies the file. You can also specify a list of files as the second argument.

The return value is the number of files whose permissions have been changed successfully. If chmod fails, $! Will contain the details of the error.

Permissions are explained in detail below.

Example

This is an example to change permissions.

use strict;
use warnings;

my $file = shift or die "Usage: $0 file\n";

# Change permissions. Permission is specified in octal.
chmod 0666, $file
  or die "Cannot change permishion $file";

Related Informatrion