By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,760 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,760 IT Pros & Developers. It's quick & easy.

Readin File permissions?

P: 16
How do i read a file permission?

i know that ls -l *filename* will list all information about the file including file permissions eg -rwxr-xr-x 1 norman.thai users 187 Jan 15 10:33 firstline...

how do i read just the file permission tho to use be used as a variable...
-rwxr-xr-x

i also understand that the file permissions can be read as binary 000 000 000...
Jan 21 '08 #1
Share this Question
Share on Google+
4 Replies

ashitpro
Expert 100+
P: 542
How do i read a file permission?

i know that ls -l *filename* will list all information about the file including file permissions eg -rwxr-xr-x 1 norman.thai users 187 Jan 15 10:33 firstline...

how do i read just the file permission tho to use be used as a variable...
-rwxr-xr-x

i also understand that the file permissions can be read as binary 000 000 000...
use this command

ls -l *filename* | awk {'print $1'}
Jan 22 '08 #2

P: 16
use this command

ls -l *filename* | awk {'print $1'}
Hey thanks for your reply. However i've not used awk or sed before and i'm not suppose to use it for this exercise. The full task is to use a file as an argument then display the permissions in a certain format like so :-

READ WRITE EXECUTE
OWNER LEE.BALLANCORE YES YES NO
GROUP USERS YES NO NO
EVERYBODY NO NO NO

i jus want to know how to read the permissions in binary so i can use if statements to create the text...if ya get me, sorry if it sounds a bit of a woffle
Jan 22 '08 #3

ashitpro
Expert 100+
P: 542
Hey thanks for your reply. However i've not used awk or sed before and i'm not suppose to use it for this exercise. The full task is to use a file as an argument then display the permissions in a certain format like so :-

READ WRITE EXECUTE
OWNER LEE.BALLANCORE YES YES NO
GROUP USERS YES NO NO
EVERYBODY NO NO NO

i jus want to know how to read the permissions in binary so i can use if statements to create the text...if ya get me, sorry if it sounds a bit of a woffle
If I am not wrong, you are trying to achieve this with C code..correct me If I am wrong.

Check out this link..

http://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html#Permission-Bits
Here are enough macros to read the permission for file.

If you are doing this under shell script..then no option other that 'awk'.
Jan 22 '08 #4

numberwhun
Expert Mod 2.5K+
P: 3,503
Another good link to read is this one.

Regards,

Jeff
Jan 23 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.