I’m trying to test if a file has the execute bit set for the owner in bash script.
I know if [ -x filename ] checks for execute permission for the User running the statement but i need to know if the owner has it. Is there a way to specify owner?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
statto get the file permissions, and parse them with another command to get the character you want.Returns something like:
EDIT: Here you go:
Returns either
-orxif the owner has execute.EDIT 2: For completion’s sake:
EDIT 3: If you prefer numerical permissions:
stat -c %a /path/to/a/filewill output 600 or 700 or whatever 3 digit base-8 number.