Get file permissions

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Get file permissions

Post by alex.barylski »

Is there a linux command which return just that? Or do I have to rely soley on "ls"?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

whats wrong with ls -l?
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

You could use the output from ls and pipe it into awk, or you could use stat, depends what you are doing.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

ls -l filename | cut -f 1 -d" "
# or
stat -c"%A" filename
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Maybe I'm missing something...but

I don't want to use 'ls' because I am calling these programatically from within PHP and I need the permissions ONLY. When you use ls -a you get a hodge podge of other stuff. I don't want to rely on parsing the listings because my research tells me the format varies from machine to machine...

Thus the reason I wanted to know if there was a command which I could use which would return nothing but permissions...

Perhaps stat would work. :)

Thanks anyways :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

So close, but yet so far away...
Post Reply