Trying to traverse a directory to change file permissions
Hello all! I don't want to say that I am a complete newbie but I am pretty "fresh of the boat."
Anyway down to the isse.... I am trying to traverse a directory to change the file/permission settings of any/all the files within that directory. Here is what I came up with (no not on my own, mostly from web sites around that show bash scripts) but I know there is an easier way of doing and am hoping that someone can help. Cheers, #!/bin/bash if [ $# -ne 3 ] then echo "Usage: 'basename $0' directory file_extension permission" exit 1 fi for filename in $(ls $1/*.$2) #this is traversing for matching files in a directory do chmod $3 $filename #this is changing the read/write properties done exit 0 |
Re: traverse ... file permissions.
From the man page for chmod:
-R, --recursive Recursively change permissions of directories and their contents. |
chmod -R is good if you want to change the permissions of files with names that fit a regular expression. For example, if you can list all of the files that you want to change using the ls command using some expression to match the names of the files then you can select those same files using chmod -R. So if you can do:
Code:
ls -R <expression> Code:
chmod -R <expression> Code:
chmod -cR <expression> Code:
find . -type f -perm +6000 -exec chmod -c a-s {} \; |
Alright then, making some head way! This helps a lot, I kind of thought recursive would come in handy in this case.
Thanks guys! |
Man tool
Hahahahaha oh man I guess I am still fairly "fresh off the boat," I didn't know of the very handy and cool tool "man." That is amazing and so very helpful!
|
All times are GMT -5. The time now is 01:35 PM. |