chmod -R doesn't seem to work

Asked by Micah Gersten

Binary package hint: coreutils

Description: Ubuntu 8.10
Release: 8.10

  Installed: 6.10-6ubuntu1
  Candidate: 6.10-6ubuntu1
  Version table:
 *** 6.10-6ubuntu1 0
        400 jaunty/main Packages
        500 intrepid/main Packages
        100 /var/lib/dpkg/status

Expect chmod -R to change mode in subdirectories.
chmod -R 644 *.php should change .php files in this dir and subdirs.

Does not change mode in subdirectories.

Question information

English Edit question
Ubuntu coreutils Edit question
No assignee Edit question
Solved by:
Lars Ljung
Last query:
Last reply:

This question was originally filed as bug #339777.

Revision history for this message
Chris Coulson (chrisccoulson) said :

chmod -R works fine for me. It is very unlikely that there is a bug here, so I'm going to convert this in to a support request in the answer tracker.

Revision history for this message
Best Lars Ljung (larslj) said :

I think you have misunderstood how the shell works. The so called glob pattern *.php is first expanded to something like "file1.php file2.php" and then chmod is called as "chmod -R file1.php file2.php". So chmod is not told to operate on any directories (unless you have directories matching the pattern of course, like dir1.php).

To do what you want to do you will have to use find, like this:

find . -name "*.php" -exec chmod 644 \{\} \;

This will search for any files that matches the specified pattern, starting in the current directory (".") and then execute the command chmod on each file (\{\} is replaced with the filename).

Revision history for this message
Micah Gersten (micahg) said :

For some reason, I thought it worked differently...not quite sure why.

Revision history for this message
Micah Gersten (micahg) said :

Thanks Lars Ljung, that solved my question.