tags:

views:

39

answers:

5

Hi, i am learning shell scriptnig, is there any way i can test the operation like checking file permission on a file.. like... i know some of the way like. searching the file through find command using permission, or in "ls...| grep 'r--r--r' smthg.. whatever permission u wan't

I have some file how i check whether the file have the required permission or not..?\

Thanks in advance..

A: 

http://tldp.org/LDP/abs/html/fto.html

seand
A: 

You could use test

The options -r -x -w test for read,execute and write permission. In a shell script the test command is usually entered as [

stacker
+1  A: 
stat FILENAME --print=%A

see man stat for more options - you can check the group/owner/etc.

gnibbler
Black Diamond
A: 

Check the man page of find. under EXAMPLES. you can see how to find files with desired permission.

ghostdog74
+3  A: 

You can do something like:

Test for execution:

if [ -x "$file" ]; then #do_something fi

Test for writting:

if [ -w "$file" ]; then #do_something fi

Test for reading:

if [ -r "$file" ]; then #do_something fi

SparkS