LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Will this command work? chmod -R 644 *.php (https://www.linuxquestions.org/questions/programming-9/will-this-command-work-chmod-r-644-%2A-php-375311/)

abefroman 10-21-2005 12:51 AM

Will this command work? chmod -R 644 *.php
 
Will this command work? chmod -R 644 *.php

I am trying to change all php files to 644 in the directory I am in now and all directories under it.

Boby 10-21-2005 01:08 AM

Hello abefrorman!

Quote:

Will this command work? chmod -R 644 *.php
Yes, this command will work, but will change only all ".php" files in that directory recursively. To chmod all files and all subdirectory of an directory you have to do "chmod -R 664 firstdirectory" and it'll change everything in it.

Hope this helped, Boby!

Dark_Helmet 10-21-2005 01:20 AM

If the goal is to change only files that end with ".php" in the current directory and all subdirectories, then you'll need something else.

As Boby mentioned, the original command "chmod -R 644 *.php" will only chmod files in the current directory that end with ".php"

Boby's command will recursively chmod any file beneath the specified directory (no matter what extension the file has).

The find command is probably the right tool for the job:
Code:

find /top/level/directory -type f -name "*.php" -exec chmod 644 {} \;
That will find every regular file that ends with ".php" in the /top/level/directory and all subdirectories and it will execute "chmod 644 <found filename>" for each one.

eddiebaby1023 10-22-2005 08:26 AM

Code:

find /top/level/directory -type f -name "*.php" -print | xargs chmod 644
is more efficient, though, as it doesn't result in spawning a new chmod(1) process for each file found.


All times are GMT -5. The time now is 12:16 AM.