Operating System - HP-UX
1834346 Members
1832 Online
110066 Solutions
New Discussion

Re: How to get the file access permissions?

 
SOLVED
Go to solution
Enrico Venturi
Super Advisor

How to get the file access permissions?

Hello colleagues,
How can I get the file access permissions, i.e. the number to use in the chmod to change the permissions on a certain file?
I mean 775, 777, and so on ...
Does it exist a command to read it for a file?
17 REPLIES 17
MarkSyder
Honored Contributor

Re: How to get the file access permissions?

Not quite sure I understand the question, but I think you're asking what the numbers stand for.

The first number is for the owner of the file, the second is for the group the owner belongs to, and the third is for all other users.

4 = read
2 = write
1 = execute.

4 + 2 = 6 = read and write etc.

man chmod should help if you need any more information.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Roberto Polli
Trusted Contributor

Re: How to get the file access permissions?

to get file permission simply
ls -l FILENAME

Peace, R.
Nicolas Dumeige
Esteemed Contributor

Re: How to get the file access permissions?

Hello,

The transformation is the following :
r --> 4
w --> 2
x --> 1
for each level owner / group / other.

I don't know if there is any utilitie to do this automatically ?

Anyway, if you're more confortable with the letters, you can use this kind of syntax :
chmod o+x filename
to give execution permession to other on filename.

Cheere

Nicolas
All different, all Unix
Jdamian
Respected Contributor

Re: How to get the file access permissions?

Try

getaccess -n file
KapilRaj
Honored Contributor

Re: How to get the file access permissions?

It has 3 digits
i.e. chmod 777 filename

First bit is the permission of Owner i.e. 4+2+1 = 7 means r(4),w(2),x(1)
Second one is for the group
Thrid one is for others

There can be one more in the bigining and it is used for setuid , sticky and stuff like that.

i.e. chmod 1777 filename

Regds,

Kaps
Nothing is impossible
Nicolas Dumeige
Esteemed Contributor

Re: How to get the file access permissions?

Enrico,

You gave evry one 1 pts.

Is becaue it's not tricky technical stuff or because you were looking for another thing ?

Nicolas

All different, all Unix
Roberto Polli
Trusted Contributor

Re: How to get the file access permissions?

Sincerely,
what a shame to get 10pts for such a question ;-)

Peace, R.
Pete Randall
Outstanding Contributor
Solution

Re: How to get the file access permissions?

Enrico,

Here is a script (originally from Jack Mahaffey) that should give you the numeric values you're looking for. Usage notes are in the comments.


Pete

Pete
Fabio Ettore
Honored Contributor

Re: How to get the file access permissions?

Ciao Enrico,

as far as I know a specific command doesn't exist to get permissions in number of a file (if I understand well your question).
Anyway 'man chmod' has all details for combinations of permissions: e.g.

0400 (= u=r) Read by owner 0200 (= u=w) Write by owner 0100 (= u=x) Execute (search in directory) by owner
0040 (= g=r) Read by group 0020 (= g=w) Write by group 0010 (= g=x) Execute/search by group
0004 (= o=r) Read by others 0002 (= o=w) Write by others 0001 (= o=x) Execute/search by others

and many more.
Also use

# umask
or
# umask -S

to see permissions set when creating a file.
Here too: for further details how to change it 'man umask'.

Hope this helps you and definitively satisfy your question.

Best regards,
Ettore
WISH? IMPROVEMENT!
Enrico Venturi
Super Advisor

Re: How to get the file access permissions?

I need a command to GET the access permission, not to SET...

getaccess -n is good but it works only for the caller user
Jdamian
Respected Contributor

Re: How to get the file access permissions?

Hi everyone.

Please read manual pages of getaccess command.
Nicolas Dumeige
Esteemed Contributor

Re: How to get the file access permissions?

Looking at Pete script that's clearer : that's for right restauration purpose, isn't it ?
All different, all Unix
Jdamian
Respected Contributor

Re: How to get the file access permissions?

Hi Enrico,

have you read the man pages of getaccess command ?

Have you found the -u and -g options ?
Enrico Venturi
Super Advisor

Re: How to get the file access permissions?

Damian,
I read the manpages of getaccess but it needs the ID of user and groups ...
I'd like to get the "number" without providing anything....
I mean:
to set: chmod 777 file_x
to get: getpermissions file_x -> 777
does getpermissions exist in UNIX?
Pete Randall
Outstanding Contributor

Re: How to get the file access permissions?

Enrico,

The numeric mode, if you read the chmod man page, is obsolescent and the preferred method nowadays is to use the symbolic mode list. I believe the reason for the emphasis on the symbolic method is because people were confused by the numeric mode and one of the reasons they were confused was that there was no command that would give them the numeric mode. That is why the script I gave you came to be: it was the only way to get the information!


Pete

Pete
Roberto Polli
Trusted Contributor

Re: How to get the file access permissions?

Well,
maybe I misunderstood, but to get unix file permissions in numerical format you must specify both a user and a group.
Let
#ls -l core
-rwxr-xr-- guest users ... core

to get something like
754 core
you must specify a user and a group
(different users gave different outputs)
if you want something like

754 guest users ... core

then you should use a script.

If you are looking for acl on disk (ext3 supports it, then you can "man acl" wishing to find out more)
Peace, R.
Bill Hassell
Honored Contributor

Re: How to get the file access permissions?

Here's a simple script method to get a file's permissions, then parse each character into the 4 digit number (includes sticky bit and SUID/SGID bits. Replace the RESULT= line with whatever you'd like to do including changing this to a function.


Bill Hassell, sysadmin