File/directory information......


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File/directory information......
# 1  
Old 12-28-2001
File/directory information......

Basically i have done created the script below, and it functions ok, it prints the access rights the user has. But i need it to print the group permissions, and other permissions, it would also be helpful if i could print the permissions in numeric form aswell, if it is possible. I have looked in a few books but they were no help.
Smilie Smilie

This is my script so far.... (This is a shortened version, i have simplified it)
Code:
Print -n "Enter a file/directory name"
read name
if [ -r $name ]
             then echo "This is file/directory is readable"
fi
if [ -w $name ]
             then echo "This is file/directory is writable"
fi
if [ -x $name ]
             then echo "This file/directory is executable"
fi
print "End"

Can ne1 help??

added code tags for readability --oombera

Last edited by oombera; 02-20-2004 at 11:07 AM..
# 2  
Old 01-03-2002
Let's use printf,

Code:
#!/bin/sh

 

printf "Enter a file/directory name\n"

read name

if [ -r $name ]

then echo "This is file/directory is readable"

fi

if [ -w $name ]

then echo "This is file/directory is writable"

fi

if [ -x $name ]

then echo "This file/directory is executable"

fi

printf "End\n"

# 3  
Old 01-03-2002
Thx 4 that negative, but wats the difference?????? Wat difference does it make??

And this possible:

But i need it to print the group permissions, and other permissions, it would also be helpful if i could print the permissions in numeric form aswell, if it is possible. I have looked in a few books but they were no help.

--------------------------------------------------------------------------------
Please post to tell me if this is possible or not? Because I have been waitin but dont look like anyone knows - which I doubt, I would have thought someone knows, guessing its not possible????????? Smilie Smilie Smilie Smilie

ADMINISTRATORS NOTE: THE TONE OF THIS POST IS AGAINST FORUM RULES. POSTER DANGEROUSLY CLOSE TO "READ ONLY" STATUS.... BE CAREFUL AND POLITE, PATIENT, OK Makaveli.2003 ?
# 4  
Old 01-04-2002
Now now now, taunting people by saying that it can't be done in a Unix forum is silly, because you can do just about anything...
For example, try :
ls -ld /tmp | cut -c2-4

That will show you the permissions that the owner has on the /tmp directory (you should see rwx)

Now, if you read the man pages to see what the "-d" option to ls does, you know why you have to use it on directories - also, RTM on cut.
# 5  
Old 01-04-2002
getacl should help you a little with this. See the man pages on the same.

Thanks to negative for his contribution though Smilie (No offence intended!)
shaik786
# 6  
Old 01-04-2002
Thanx LivinFree - that was great, but this is what I need help with:


1) Need to be able to print "group permissions" e.g if -rwxr-x--x
need to print "r-x"or whatever it is for that file/directory


2) Need to be able to print "other permissions" e.g. if -rwxr-x--x
need to print "--x" or whatever it is for that file/directory


3) Need to print the permissions numberically e.g. 700


I looked on man pages but they werent much help

Please help Smilie
# 7  
Old 01-04-2002
Sorry, but I just been experimenting and thanx to LivinFree worked it out, but I still need a little help. This is wat ive worked out:

1) Need to be able to print "group permissions" e.g if -rwxr-x--x
need to print "r-x"or whatever it is for that file/directory


This is what i did: ls -ld filename | cut c5-7 (is this right)


2) Need to be able to print "other permissions" e.g. if -rwxr-x--x
need to print "--x" or whatever it is for that file/directory


This is what I did: ls -ld filname | cut c8-11 (is this right)


But I still need help with :

3) Need to print the permissions numberically e.g. 700
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create file and file content based existing information?

Hi Gurus, I am SQL developer and new unix user. I need to create some file and file content based on information in two files. I have one file contains basic information below file1 and another exception file file2. the rule is if "zone' and "cd" in file1 exists in file2, then file name is... (13 Replies)
Discussion started by: Torhong
13 Replies

2. UNIX for Dummies Questions & Answers

Grep? - using a file of terms to search another file when the information is on a different line

I have a flat file that looks like this, let's call it Chromosome_9.txt: FT /Gene_Name="Guanyl-Acetylase 9" FT /Gene_Number"36952" FT /Gene_Name="Endoplasmic Luciferase" FT /Gene_Number"36953" FT ... (4 Replies)
Discussion started by: Twinklefingers
4 Replies

3. UNIX for Dummies Questions & Answers

How can I use my code to gather information from a file in a completely different directory?

I need my code to compare two different files that are in two completely different directories, How can I do this? So for example, my code will look at file1 which is in my home directory, and compare the files with those from file2 that is in /abc/adf/adr/afc/adf/file2... does that make sense? (1 Reply)
Discussion started by: castrojc
1 Replies

4. Shell Programming and Scripting

reading a file extracting information writing to a file

Hi I am trying to extract information out of a file but keep getting grep cant open errors the code is below: #bash #extract orders with blank address details # # obtain the current date # set today to the current date ccyymmdd format today=`date +%c%m%d | cut -c24-31` echo... (8 Replies)
Discussion started by: Bruble
8 Replies

5. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

6. Shell Programming and Scripting

Only the required tag information the XML file file

Hi i have a single line xml file having many account no tag, from which i need only the account no from the tag. any one can help on this. below is the xml file: ... (2 Replies)
Discussion started by: Saravanapk
2 Replies

7. Shell Programming and Scripting

Generating an xml having information related to files in the directory

Hi all, Have to generate an xml having information related to files in the directory Suppose i have file file1.xml (datafile) file2.xml (datafile) file3.xml (metafile) Now i need to generate an xml in the format >> <?xml version="1.0" encoding="UTF-8"?> <AuditFile Version="2.0">... (8 Replies)
Discussion started by: abhinav192
8 Replies

8. UNIX for Dummies Questions & Answers

Read directory and fill a file with this information

Hello All, Got a question to make a script what reads a directory and put the file names from that directory in a file with some extra text. ls /tempdir output is: file1.gfh file2.txt file4.zzz these file names (always with an extention) must be placed in a line and written to... (2 Replies)
Discussion started by: ToXiQ
2 Replies

9. UNIX for Dummies Questions & Answers

why does tar sometimes include directory information?

hi, say I have dirA/file1 dirB/file2 and I tar them up, and then do zcat Tar.tar | tar tvf - Sometimes I will see: dirA/ dirA/file1 dirB/ dirB/file2 yet other times I will see (4 Replies)
Discussion started by: JamesByars
4 Replies

10. UNIX for Dummies Questions & Answers

date information of a directory

when i list the content of a directory date informations are also listed (ls -ltr) for included files and directories. for example: i see the date Jun 29 14:43 for one of the included directory, but when i look into the files contained in this directory i cannot see any file with this... (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies
Login or Register to Ask a Question