[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 591
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

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