hello,
I have 20 directories under /home folder and I need to chmod to all of them as a+w... how can I do that without doing them manually?
this is what I want to look like
root#chmod a+x ${mydir}
where mydir is the variable name which should come from file one at a time.
Thanks,
Data Sheet
chmod through loop
Assuming all dirs are in a file named dirlist - one per line :
or
If you want to recursively change permissions on all dirs under /home, then use this command:
find /home -type d -exec chmod a+x {} \;
Code: Select all
for dir in `cat dirlist`
do
chmod a+x $dir
done
If you want to recursively change permissions on all dirs under /home, then use this command:
find /home -type d -exec chmod a+x {} \;
-
- Site Admin
- Posts: 5132
- Joined: Fri May 02, 2003 10:24 am
- Location: Karachi
- Contact:
use xargs. it's there to help you!
xargs chmod a+w < dirlist
find /home -type d -print | xargs chmod a+w
the difference between find ... -exec ... and find ... | xargs ... is that the former runs the chmod command for every directory, and the latter runs it for every 5,000 or so directories. it's a lot faster that way.
xargs chmod a+w < dirlist
find /home -type d -print | xargs chmod a+w
the difference between find ... -exec ... and find ... | xargs ... is that the former runs the chmod command for every directory, and the latter runs it for every 5,000 or so directories. it's a lot faster that way.
Asslam 0 alikum!!
If you want to change the permission of only directries then use command as mentioned by lambda
If you want ot change permisson of all files and directories under /home it is so simple.
chmod -R a+rw /home
Allah Hafiz
If you want to change the permission of only directries then use command as mentioned by lambda
If you want ot change permisson of all files and directories under /home it is so simple.
chmod -R a+rw /home
Allah Hafiz
**********************************************
As-Salaatu was-Salaamu Alaika Ya Sayyidi Ya Rasool ALLAH
**********************************************
As-Salaatu was-Salaamu Alaika Ya Sayyidi Ya Rasool ALLAH
**********************************************
Point made by Lambda about speed of execution is an important one. If one is dealing with hundreds or thousands of files/dirs, then xargs is the tool to use. Here is a simple comparison:
# time find . -print -exec ls {} \; > /dev/null
real 0m10.108s
user 0m2.050s
sys 0m5.460s
# time find . -print | xargs ls > /dev/null
real 0m0.309s
user 0m0.090s
sys 0m0.230s
0.3 secs elapsed time against 10 secs is about 30 times faster.
# time find . -print -exec ls {} \; > /dev/null
real 0m10.108s
user 0m2.050s
sys 0m5.460s
# time find . -print | xargs ls > /dev/null
real 0m0.309s
user 0m0.090s
sys 0m0.230s
0.3 secs elapsed time against 10 secs is about 30 times faster.