Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

batch chmod

Status
Not open for further replies.

Masali

Programmer
Jun 19, 2002
143
SE
Hi,

I have lots of files and directories that needs to be chmod'ed to 666. The problem is that only directories and files matching certain names that is to be chmod'ed. It should also be recursive search for the files and directories. Is it possible to do this?

Masali
 
You'd probably need a script to do it but it will really only work if the file and directory names can be matched using regular expressions. If you have to type them in manually, you might as well do it via the command line.
 
Code:
find $top_dir -name $pattern -exec chmod 666 {} \;
or
Code:
find $top_dir -name $pattern |xargs chmod 666
 
If you can devise a pattern to fit the name criteria, the command is simple:

# find / -type f -name "*abc*" -exec chmod 666 {} \;

# find / -type d -name "*abc*" -exec chmod 777 {} \;

It's doubtful that you really meant "666" for directories, as this would give you lots of grief. So, I gave you two different commands. You should try each first and just create a listing of the matched files/directories. That way, you don't open up permissions on something which should remain restricted. Create a list like this:

# find / -name "*abc*" -print > found.list

 
i used motoslide's tips. I am sure the others worked as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top