Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
chmod directorys and files in subfolders
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
SarahS93
Guru
Guru


Joined: 21 Nov 2013
Posts: 455

PostPosted: Tue Jul 26, 2016 9:50 pm    Post subject: chmod directorys and files in subfolders Reply with quote

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
View user's profile Send private message
SarahS93
Guru
Guru


Joined: 21 Nov 2013
Posts: 455

PostPosted: Tue Jul 26, 2016 10:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 13496

PostPosted: Wed Jul 27, 2016 1:04 am    Post subject: Reply with quote

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
View user's profile Send private message
alinefr
Tux's lil' helper
Tux's lil' helper


Joined: 05 Jul 2009
Posts: 111
Location: São Paulo, Brasil

PostPosted: Wed Jul 27, 2016 1:34 am    Post subject: Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 13496

PostPosted: Wed Jul 27, 2016 3:34 am    Post subject: Reply with quote

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
View user's profile Send private message
SarahS93
Guru
Guru


Joined: 21 Nov 2013
Posts: 455

PostPosted: Wed Jul 27, 2016 5:26 am    Post subject: Reply with quote

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
View user's profile Send private message
Akkara
Administrator
Administrator


Joined: 28 Mar 2006
Posts: 6602
Location: &akkara

PostPosted: Wed Jul 27, 2016 5:44 am    Post subject: Reply with quote

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

_________________
Isn't it odd that no job openings ever list being potty-trained as one of the requirements?
Back to top
View user's profile Send private message
py-ro
Veteran
Veteran


Joined: 24 Sep 2002
Posts: 1733
Location: St. Wendel

PostPosted: Thu Jul 28, 2016 11:24 am    Post subject: Reply with quote

No find needed...

Code:
chmod ug=rwX,o=rX -R $dir
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum