Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

chmod

Status
Not open for further replies.

cginewbie

Programmer
Jan 20, 2002
24
US
How do you change mode of files from cgi application?
like data/
data/ddd
if data is 0777, can you change all subdirectories and files inside data to 0777 also by CGI application? or it has to be done every signle one from the cmd line?
 
Perl comes with a [tt]chmod[/tt] subroutine. See the [tt]perlfunc[/tt] pages for a full explanation. You can pass an array of files to this subroutine, for example:
Code:
my @files = qw( data/ddd data/eee );
$mode = 0777; # octal number
$changed = chmod( $mode, @files );
You could also use [tt]chmod[/tt] along with the [tt]File::Find[/tt] package to recurse through your directory. Something like:
Code:
use File::Find;

sub change {
    my $mode = 0777;
    chmod $mode, $_ if -f;  # change if regular file
}

# list of directories
my @dirs = qw( a b );

# recursively modify permissions on regular files
find( \&change, @dirs );
Cheers, Neil
 
Yes, I understand that we can use chmod to change file permissions, but I also look for a way to chmod for DIRECTORY so that I can write files to.
It is very difficult to go to 100's directory and chmod them just to be able to write to them.

The problem arise because I used a image gallery program, and this program need the all photo directories to be chmod'ed to 0777 so that they can write information and upload files to. And I have 1000's, I mean 1000's, categories. It will take me the whole day just to do that.
So I would like to write small function that automatically chmod every DIRECTORY for me to 0777, so that I can use the program.

Really appreciate if you can point me to any direction.
 
chmod works for directories too

change a single drectory:
Code:
chmod 0777, $ARGV[0];

Recursively change directories below a top-level directory:
Code:
use File::Find;

sub change_dirs {

    chmod 0777, $_ if -d;

}

find( \&change_dirs, $ARGV[0] );
Cheers, Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top