Results 1 to 3 of 3
How can I iterate over all the files in the current directory to check for certain permissions? This is what I have:
Code:
#!/bin/bash
for file in *.tar.gz
do
if ...
- 01-14-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 2
Bash script: make sure all files have certain permissions
How can I iterate over all the files in the current directory to check for certain permissions? This is what I have:
But this only checks that the current user has read permissions for each file. I want to check that the group "others" has read permissions for each file. How can I do this? Is there a built in function to check if a file has read permissions for the "others" group?Code:#!/bin/bash for file in *.tar.gz do if [ -r "$file" ] then echo "$file is readable" else echo "$file is NOT readable" fi done
Otherwise, I thought I might be able to use this
And parse the output "744" and make sure the 3rd number is between 4 and 7 (since the octals 4-7 have read permissions for others)Code:$ stat --format=%a file 744
Thanks
- 01-14-2011 #2Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,695
Read:
Code:man find
- 01-14-2011 #3Just Joined!
- Join Date
- Jan 2011
- Posts
- 2
Beautiful. I ended up using this script:
#!/bin/bash
non_readable=`find . -name '*.tar.gz' ! -perm -a=r -printf "%f "`
if [ ${#non_readable} -gt 0 ]; then
echo "These files do not have read permissions for all:"
ls -l ${non_readable}
fi


Reply With Quote