Visit Our UNIX and Linux User Community


file permissions using shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file permissions using shell scripting
# 1  
Old 10-02-2007
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  
Old 10-02-2007
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  
Old 10-02-2007
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  
Old 10-02-2007
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  
Old 10-02-2007
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  
Old 10-02-2007
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  
Old 10-02-2007
my condolences for a poor choice in employment...
Quote:
Originally Posted by Anonymous
"Efficiency is intelligent laziness."

Previous Thread | Next Thread
Test Your Knowledge in Computers #160
Difficulty: Easy
The Internet Autonomous Network Authority (IANA) is responsible for maintaining the official assignments of Internet port numbers.
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

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

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

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

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

7. Shell Programming and Scripting

file operations in shell scripting

hi All, my query... 1.I Have to search for the files in the root directory. 2.i have to search for a pattern in all the files in the root directory and then replace them with a new pattern. 3.Rename the file Explanation: if ABC is the root folder and has 3 subfolders and there are 15... (9 Replies)
Discussion started by: adityamahi
9 Replies

8. Shell Programming and Scripting

.def file in HP-UX Shell scripting

Hi Pals, I need some information related .def file in HP-Ux shell scripting. What actaully a .def file contains. It is having all definitions of some functions. But what is the relationship between a .def file and shell script. Can anyone give some examples. Thanks in Advance. Best... (1 Reply)
Discussion started by: manu.vmr
1 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