Click to See Complete Forum and Search --> : chmod -r -x * & exclude directories.
Nexist
01-09-2002, 07:00 PM
Can this be done? I copied a bunch of files from a Windows Partition which were all mearked as executable. I then did a recursive chmod to set the execution bit off. After hitting return I realized the horrible mistake, as all directories became unlistable.
Is there a way to specify for Chmod to recurse into any & all sub directories and modify the files within those directories without applying to the directories themselves?
I don't know grep that well yet, & I have a sinking suspicion that grep is the tool I will need... :(
Taking the exectable flag off a directory (what the hell is that for anyway?!) shouldn't make it unlistable..
And unless I'm confused, couldn't you just cd into the directory then to the chmod-R xxx, cd out, cd in another and repeat?
slapNUT
01-10-2002, 02:25 PM
Here's one right out of Linux Shells by Example. Save it in your path, make it executable. Go into the directory you want to chmod the files in. Run program with * parameter i.e. <program> *.
#!/bin/bash
for FILE
do
if [ -f $FILE -a ! -x $FILE ] # another way if [[ -f $FILE && ! -x $FILE ]]
then
chmod +x $FILE
echo "Changing file $FILE..."
fi
done
Note this is checking to see if the file is NOT executable then if it isn't chmod to make it executable. To modify it to do the opposite just remove the "!" in the test and change the chmod to -x. I don't think it recurses into directories but thats a project for the *****ious. It could be modified to chmod the directories... HINT: the -f stands for file a -d would test to see if $FILE was a directory.
HTH
2thumbs
01-10-2002, 06:27 PM
Originally posted by 7:
<STRONG>Taking the exectable flag off a directory (what the hell is that for anyway?!) shouldn't make it unlistable..
And unless I'm confused, couldn't you just cd into the directory then to the chmod-R xxx, cd out, cd in another and repeat?</STRONG>
The executable flag on a directory means as much as "access". If you dont have x, then you can't list the contents of the directory.
Doing it seperatedly for each dir would be a waste of time if you have like 50 directories and subfolders within them :)
Thanks 2thumbs, strange that I've been using Linux for 2 years+ and I never knew that!
Stupid post..
2thumbs
01-10-2002, 06:53 PM
It's ok.. I step on my own toes quite frequently also... and I do it for a living :o
AdaHacker
01-10-2002, 08:50 PM
No grep needed. Just use find. This command
find $DIRNAME -type f -exec chmod 640 {} \;
will recurse int $DIRNAME, find everything that's just a regular file, and do a chmod 640 on it. The '-type f' tells find to return regular files, while the -exec performs the command after it. The {} in the chmod command stands for the file currently being processed. You must end the exec option with a semi-colon, which you'll probably have to escape.
You could modify this to change permissions on just the directories by changing the '-type f' to '-type d', for directory.
You can read more in the man page, but I find the reference and examples in Linux in a Nutshell much better.