• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 607
  • Last Modified:

chmod for directories and files

i have a directory there ar a lot of subdirectory in it and a lot of files. i want to set 0755 for directories and 0644 to files. what command i have to use.


i find that commands. but not works.

find . -type f -print0 | xargs -0 chmod 444

find . -type d -print0 | xargs -0 chmod 755
0
phparmy
Asked:
phparmy
2 Solutions
 
omarfaridCommented:
did you try this

find . -type f | xargs  chmod 444

find . -type d | xargs chmod 755
0
 
hemmiCommented:
Are you sure? The command is just perfect! Have you run just the "find" command without the chmod? Does the find by itself shows any output?
0
 
omarfaridCommented:
for files, change it to

find . -type f | xargs  chmod 644
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
hemmiCommented:
Don't let yourself be fooled! The -print0 in combination with the -0 of xargs is just perfect. People should know how to handles filenames with spaces before answering here!!!!!!!!!
0
 
hemmiCommented:
I forgot:
there are old versions of xargs, that need "--null" instead of "-0"
and what is actually the output of the command? Nothing? Or does it wait forever?

0
 
phparmyAuthor Commented:
thanks today worked perfectly.
0
 
omarfaridCommented:
hemmi:

to whom you are posting these lines?

"Don't let yourself be fooled! The -print0 in combination with the -0 of xargs is just perfect. People should know how to handles filenames with spaces before answering here!!!!!!!!!"
0
 
hemmiCommented:
He used the -print0 in combination with -0 of xargs which is the correct command!
Your suggestion was much worse compared to what he did, because it always fails on filenames with spaces!
0
 
omarfaridCommented:
again, to whom your comment?
0
 
TintinCommented:
omarfarid, hemmi is addressing you.

Hemmi's point is that the original

find . -type f -print0 | xargs -0 chmod 444
find . -type d -print0 | xargs -0 chmod 755

should work just fine as it handles dirs/filenames with spaces, whereas doing

find . -type f | xargs  chmod 444
find . -type d | xargs chmod 755

will fail on any dir/file with a space in the name.

0
 
omarfaridCommented:
Thank you Tintin, I could get that much from his comment. But, I did not like the way he commented. If he thinks that some answer is not correct, etc. he should not be offensive.

See how he commented:

"People should know how to handles filenames with spaces before answering here!!!!!!!!!""
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now