file permissions using shell scripting


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
file permissions using shell scripting

Hi
I am trying to use shell script to display file permissions, and I can do it fine for the current user logged in, but now I want to view all file permissions for the Owner of the file, Group users and everyone, so it will look something like this:
-----------------READ WRITE EXECUTE
OWNER Username ---YES---YES---NO
GROUP USERS ---YES---NO---NO
EVERYBODY ---NO----NO---NO

Below is what I have so far.
Code:
echo -n "please enter file name : "
read file 
[ -w $file ] && W="Write = yes" || W="Write = No"
[ -x $file ] && X="Execute = yes" || X="Execute = No" 
[ -r $file ] && R="Read = yes" || R="Read = No" 
echo "$file permissions $W $R $X"

so my question is how do I find out the other permissions of the file?.

Any hints of tips would be greatly appreciated.

thanks

Last edited by barbus; 10-02-2007 at 06:52 AM..
# 2  
Finding permissions

I confess I think you are making life overly difficult for yourself.

To display the owner, group and permissions on a bunch of files you can use find to get the files and then exec to display the info.....

find <dir> -exec ls -l {}\;

If you want to chop out different columns from the ls -l output then awk will be a good avenue of exploration.

I think that rwxr-wr-- is just as understandable as
yesyesyyes yesnoyes yesnono

If you do not want to include dirs in the find then...

find <dir> ! -type d -exec ls -l {}\;
# 3  
I could do this easy with awk, but my unreasonable employer wont let me use with awk or sed Smilie.

He wants a simple script to view it with yes no so other non IT related departments can understand it.

but thx for the reply, ill try out your sugession.
# 4  
how would i search the strings like rwxr-wr--, or put it in a variable. if i can achieve this i can just search the string for certain characters and print out statment based on those characters.
# 5  
Quote:
Originally Posted by barbus
I could do this easy with awk, but my unreasonable employer wont let me use with awk or sed Smilie.
Your teacher is now your employer ?

Jean-Pierre.
# 6  
I started working here last week, and it’s a trainee position, where I am expected to under take a course which is involves doing these tedious tasks as part of the job, my boss is kinda my teacher, I should have said mentor though its still the same thing.

And doesn’t want me using awk or sed as they “promote laziness from programmer prospective” -_-


is it possible to redirect the string of permissions like rwxr-wr-- to a variable/tmp?

Last edited by barbus; 10-02-2007 at 08:18 AM..
# 7  
my condolences for a poor choice in employment...
Quote:
Originally Posted by Anonymous
"Efficiency is intelligent laziness."
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #546
Difficulty: Medium
In computer science, an operator takes the values of its operands and combines them in some way to produce a new value.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

2. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. Shell Programming and Scripting

Display the First and Last name from a file using shell scripting

I am new to shell scripting and doing a similar thing @ work Stan:Smith:Detroit:MI Jim:Jones:Farmington Hills:MI Jack:Frost:Denver:CO Sue:Apple:New York:NY Cindy:Thompson:Battle Creek:MI John:Smith:Denver:CO George:Jones:New York:NY Need to create a shell script This script will display... (1 Reply)
Discussion started by: jakemathew
1 Replies

4. 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

5. 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

6. Homework & Coursework Questions

Shell scripting/working with a file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1. Write a shell script that will work with a file from the command line. The program should: a. Check... (4 Replies)
Discussion started by: Jagst3r21
4 Replies

7. Shell Programming and Scripting

Shell scripting - need to arrange the columns from multiple file into a single file

Hi friends please help me on below, i have 5 files like below file1 is x 10 y 20 z 15 file2 is x 100 z 245 file3 is y 78 z 23 file4 is x 100 (3 Replies)
Discussion started by: siva kumar
3 Replies

8. Shell Programming and Scripting

Need to create file from shell scripting

Hi, I want to create a file from a shell script. the data for the file will come from variables. that is the file format is like, var1-value var2_value ... that is, var1_value should be placed in first 10 spaces and var2_value should be placed in next 8 columns like that. is there... (4 Replies)
Discussion started by: smr_rashmy
4 Replies

9. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

10. UNIX for Dummies Questions & Answers

file activity (open/closed) file descriptor info using KORN shell scripting

I am trying to find a way to check the current status of a file. Such as some cron job processes are dependent on the completion of others. if a file is currently being accessed / modified or simply open state I will wait until it is done being processed before attempting the next process on that... (3 Replies)
Discussion started by: Gary Dunn
3 Replies

Featured Tech Videos