View previous topic :: View next topic |
Author |
Message |
SarahS93 l33t
Joined: 21 Nov 2013 Posts: 693
|
Posted: Tue Jul 26, 2016 9:50 pm Post subject: chmod directorys and files in subfolders |
|
|
How can i search for all subfolders in a folder an change all folders to 775, and how can i search for all files in the subfolders for files and chmod them to 664 ? |
|
Back to top |
|
|
SarahS93 l33t
Joined: 21 Nov 2013 Posts: 693
|
Posted: Tue Jul 26, 2016 10:44 pm Post subject: |
|
|
Code: | chown -cR <user>.<group> * && find . -type d -print0 | xargs -0 chmod 775 && find . -type f -print0 | xargs -0 chmod 664 |
works fine, but if i run this on round about 1.000.000 files i can see that this way makes a lot of writes on the disk.
is there a way with more read and less write on my disk? |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21633
|
Posted: Wed Jul 27, 2016 1:04 am Post subject: |
|
|
You could modify the find expression so that it does not print objects for which the mode is already as desired. Other than that, how would you reduce writes without skipping some necessary changes? |
|
Back to top |
|
|
alinefr Tux's lil' helper
Joined: 05 Jul 2009 Posts: 113 Location: São Paulo, Brasil
|
Posted: Wed Jul 27, 2016 1:34 am Post subject: |
|
|
find has the -exec argument, so you don't need those pipes.
find . -type d -exec chmod 775 {} \; && find . -type f -exec chmod 664 {} \; |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21633
|
Posted: Wed Jul 27, 2016 3:34 am Post subject: |
|
|
Using -exec is much worse than using xargs. The form of -exec you suggest will run one chmod per entry found. Using xargs will batch up the calls to chmod. |
|
Back to top |
|
|
SarahS93 l33t
Joined: 21 Nov 2013 Posts: 693
|
Posted: Wed Jul 27, 2016 5:26 am Post subject: |
|
|
find . -type d -exec chmod 775 {} \; && find . -type f -exec chmod 664 {} \;
works too but
chown -cR <user>.<group> * && find . -type d -print0 | xargs -0 chmod 775 && find . -type f -print0 | xargs -0 chmod 664
is 10 times faster and do not make so many writes on the disk.
How could i modify the find expression so that it does not print objects for which the mode is already as desired ? |
|
Back to top |
|
|
Akkara Bodhisattva
Joined: 28 Mar 2006 Posts: 6702 Location: &akkara
|
Posted: Wed Jul 27, 2016 5:44 am Post subject: |
|
|
SarahS93 wrote: | How could i modify the find expression so that it does not print objects for which the mode is already as desired ? |
Use the -perm test of find:
Code: | find . -type d -a '!' -perm 775 |
_________________ Many think that Dilbert is a comic. Unfortunately it is a documentary. |
|
Back to top |
|
|
py-ro Veteran
Joined: 24 Sep 2002 Posts: 1734 Location: Velbert
|
Posted: Thu Jul 28, 2016 11:24 am Post subject: |
|
|
No find needed...
Code: | chmod ug=rwX,o=rX -R $dir |
|
|
Back to top |
|
|
|