Script to run chown on all folders and setting the owner as the folder name minus the trailing /
Posted
by
Shikoki
on Server Fault
See other posts from Server Fault
or by Shikoki
Published on 2012-10-20T09:01:18Z
Indexed on
2012/10/20
11:04 UTC
Read the original article
Hit count: 201
Some numpty ran chown -R username
. in the /home folder on our webserver thinking he was in the desired folder. Needless to say the server is throwing a lot of wobbelys.
We have over 200 websites and I don't want to chown them all individually so I'm trying to make a script that will change the owner of all the folders to the folder name, without the trailing /.
This is all I have so far, once I can remove the / it will be fine, but I'd also like to check if the file contains a . in it, and if it doesn't then run the command, otherwise go to the next one.
#!/bin/bash
for f in *
do
test=$f;
#manipluate the test variable
chown -R $test $f
done
Any help would be great!
Thanks in advance!
© Server Fault or respective owner