check if user has read permissions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check if user has read permissions
# 1  
Old 11-10-2008
check if user has read permissions

hi all,
i have a script (ksh) which reads data from log files, how do i check to see if the user which is executing the script has read permissions to the file ?


thanks in advance.
# 2  
Old 11-10-2008
Code:
if [ -r "$FILE" ]
then
  echo You have read permission
else
  echo You do not have read permission
fi

# 3  
Old 11-10-2008
Here are a few useful conditions:


-b file = True if the file exists and is block special file.
-c file = True if the file exists and is character special file.
-d file = True if the file exists and is a directory.
-e file = True if the file exists.
-f file = True if the file exists and is a regular file
-g file = True if the file exists and the set-group-id bit is set.
-k file = True if the files' "sticky" bit is set.
-L file = True if the file exists and is a symbolic link.
-p file = True if the file exists and is a named pipe.
-r file = True if the file exists and is readable.
-s file = True if the file exists and its size is greater than zero.
-s file = True if the file exists and is a socket.
-t fd = True if the file descriptor is opened on a terminal.
-u file = True if the file exists and its set-user-id bit is set.
-w file = True if the file exists and is writable.
-x file = True if the file exists and is executable.
-O file = True if the file exists and is owned by the effective user id.
-G file = True if the file exists and is owned by the effective group id.
file1 –nt file2 = True if file1 is newer, by modification date, than file2.
file1 ot file2 = True if file1 is older than file2.
file1 ef file2 = True if file1 and file2 have the same device and inode numbers.
-z string = True if the length of the string is 0.
-n string = True if the length of the string is non-zero.
string1 = string2 = True if the strings are equal.
string1 != string2 = True if the strings are not equal.
!expr = True if the expr evaluates to false.
expr1 –a expr2 = True if both expr1 and expr2 are true.
expr1 –o expr2 = True is either expr1 or expr2 is true.
#Find files with 0 size and delete
find /path/to/files -size 0 -ok -exec rm {} \;
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check the file permissions using python scripting

Hi, For a particular set of files, am trying to check if they are writable. i.e., checking whether they are having permissions greater than 755. Am able to check this using the statement: "if (os.path.isfile(FILE_PATH) and (os.stat(FILE_PATH).st_mode & 0777) == 0777):" But the problem... (1 Reply)
Discussion started by: arjun_arippa
1 Replies

2. Programming

To check the file permissions using python scripting

Hi, For a particular set of files, am trying to check if they are writable. i.e., checking whether they are having permissions greater than 755. Am able to check this using the statement: "if (os.path.isfile(FILE_PATH) and (os.stat(FILE_PATH).st_mode & 0777) == 0777):" But the problem here... (0 Replies)
Discussion started by: arjun_arippa
0 Replies

3. Homework & Coursework Questions

Check the permissions user

i have some question for example: suppose we have the Public folder as follows: https://www.unix.com/attachments/shell-programming-scripting/2759d1334070669-check-permissions-linux-user-capture.png If user enter: -Kenshin or /home/kenshin/Public output: abc: kenshin: rw my shell:... (1 Reply)
Discussion started by: kingkner
1 Replies

4. Shell Programming and Scripting

Check the permissions linux user

i have some question for example: suppose we have the Public folder as follows: https://www.unix.com/attachment.php?attachmentid=2759&stc=1&d=1334070669 If the user enter: -Kenshin or /home/kenshin/Public output: abc: kenshin: rw my shell: echo "Enter User:" read user ... (3 Replies)
Discussion started by: kingkner
3 Replies

5. Solaris

add a ftp user with read and write permissions on a directory

hi all how I can create an ftp user in solaris 10 and have read and write permission on a directory. Thanks. (1 Reply)
Discussion started by: luisfja
1 Replies

6. Shell Programming and Scripting

How to check file permissions from a script.

hello, I have to write a script to run the other script inside it.So iam planning to write like this? first check the perimissions of the file. Alogorthim ---------- if(!filepermissions == execute) then echo" Permissions denined" else execute the script. file name is : load_mf.sh... (1 Reply)
Discussion started by: rajkumar_g
1 Replies

7. Shell Programming and Scripting

How to check the mail permissions

Hi - I am trying to send email from unix box but none were delivered. I have tried multiple commands like mailx, mail or sendmail. But none of them worked. can you please let me know how to check if I have the right permissions to send the mail or not? (1 Reply)
Discussion started by: ahmedwaseem2000
1 Replies

8. Shell Programming and Scripting

Using grep - check the permissions of the file searched

What I need to do is: I need to use the grep command to search for pattern in directory and sub-directories. And also I need to show the permission of file been seached by the grep command. Could any one please suggest me? ----------------- $> cat file1.txt A -----------------... (8 Replies)
Discussion started by: Johny001
8 Replies

9. UNIX for Dummies Questions & Answers

Default read/write/execute permissions

I am perplexed that my script execution is not always consistent in creating new files. Specifically, my group read/write/execute permissions. For instance, take a look at the following: -rw-rw---- 1 jg dp 18648 Aug 22 10:06 nx081508.txt -rw-rw---- 1 jg dp 22422 Aug 22 10:06... (1 Reply)
Discussion started by: joeyg
1 Replies

10. Programming

read permissions by VC++

do you know how to read file permissions (such as lrwxrwxrwx) by VC++ on Windows OS (ftp connection)? I use a windows program (coreftp) to download and upload files for my host, this program displays permissions of files, so file permissions can be read by VC++, but I don't know how. any help... (1 Reply)
Discussion started by: hello20009876
1 Replies
Login or Register to Ask a Question