Recursively chmod directories
...how do I?
I have a dir structure with .html, .php etc. I can use: chmod -R 644 *.html chmod -R 755 *.php ok, but can't find a way to change all dirs to e.g. 755 tried getting a list of dirs and pipe to chmod: sudo ls -R | grep :$ | sed s/:// | chmod 755 (am running ubuntu) just comes back chmod: missing operand after `755' yours frustratedly Simon. |
chmod
you can just cd to the directory you want to change it's permissions and type:
chmod -R 755 ./ |
Piping a list of directories, that literally are strings separated by newlines, does not tell to chmod what to do. You can use xargs to build and execute commands from the standard input, as in
Code:
sudo ls -R | grep :$ | sed s/:// | xargs chmod 755 Code:
sudo find ./test_dir -type d -exec chmod 755 {} \; |
You have directory names with extensions like .html?? seems unusual, but I'm not sure how it is relevant.
chmod -R will change everything (directories and files)--I think you are saying you want to change directories only. I would suggest a loop starting with: for f in `ls -R` do ... ... done what this does is make a list of values in the variable "f", you can then test each one using--eg--the "file" command. If the test shows it is a directory, then: chmod 755 $f Note: In your other code, you were grepping using ":$" I assume you meant this to mean ":" at the end of the line. Trouble is, the ":" is not part of the actual directory name---I suspect it is just the character that your terminal uses to designate a directory. |
Code:
for i in i.e print only the 9th field of all but the first 2 lines ? It would make the above script look a bit shorter. |
I've always done it in two steps. The -print0 argument to find and the -0 argument to xargs mean that the list of files is de-limited with the NULL character - this can save you problems if there are file names with spaces in:
Code:
find /path/to/files -type d -print0 |xargs -0 chmod 755 |
IGNORE ME: someone else posted this higher up...
why not just Code:
find . -type d -exec chmod 0755 {} \; |
All times are GMT -5. The time now is 03:25 PM. |