• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Unix recursive permission change on files ONLY

NivekC4

Golden Member
In Unix, I was wondering if there was a way to change all file permissions under a certain directory to a certain permission (444) while leaving the directories' permissions as they are (2775).

The chmod -R 444 /<directory>/<directory>/* will change BOTH directories and files. I just want to change the files.

thanks for the help.
 
For tricky chmod stuff like that I don't realy have a proper answer.

I'll also found that using the u+x type things resolve quite a few issues over complicated stuff, but still the recursive directory stuff sucks.

Although there are some ugly scripts I can whip up. (I am a bad and lazy programmer with little knowledge or skills, btw.)


This script is named "chmod.not.dir.bash"
#! /usr/bin/env bash

DIRPATH=$2
PERMIS=$1

find $DIRPATH | while read i
do
if file "$i" |grep -v directory > /dev/null
then
chmod $PERMIS "$i"
fi
done

Then you would go:
chmod.not.dir.bash 444 /were/you/want/to/go

To test to make sure that it'll do what you want:
#! /usr/bin/env bash

DIRPATH=$2
PERMIS=$1

echo "going to do a recursive chmod on $DIRPATH, with permissions $PERMIS"
find $DIRPATH | while read $i
do
if file "$i" |grep directory > /dev/null
then
echo "$i is a directory and will be ignored"
fi
done

Notice that in the first one used 'grep -v' and the second one just used 'grep'

I think that will work, test it out first before using it on a thing with a few thousand files...
 
Originally posted by: BingBongWongFooey
a compromise:

find . -type f | while read i; do chmod 444 "$I"; done

Mine handles whitespace fine. 😛

xargs with -0 will only terminate at a null.
 
And it should be faster because it'll call chmod via xargs with more than one file at a time, meaning less forks.
 
Originally posted by: BingBongWongFooey
a compromise:

find . -type f | while read i; do chmod 444 "$I"; done

I like that. Normally I stay away from from "find" switches...

I just use it like a "ls -R" should work.... Whoever thought that to list the ls output the way it is should be drawn and quartered.


/directory/name:
file1 file2
file3 file4
file5 file6

/directory/name/2:
file12 file22
file32 file42
file52 file62

etc etc...

How the hell am I suppose to use that???

Oh well, I suppose I should read "man find" that -type switch seems very usefull.
 

cd dir_you_want_to_start_at
find . -type f -exec chmod 444 {} \;

geez guys, don't any of you know how to use find? 😛
 
Back
Top