Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"ls" can't display octal permissions ?!?!

70 views
Skip to first unread message

Martin Krischik

unread,
Feb 12, 2008, 7:27:49 AM2/12/08
to
Hello

Currently I am trying to create some Solaris installations packages and
to do so I need the know the current file permissions for "/etc/env".

I thought "ls -l -d -? /etc/env'" with '-?' being an option I don't know
yet and which will change the display format from "drwxrwxrwt" to octal.

Now I read "ls --help", "man ls", "info ls", Wikipedia and
http://www.linux-command.com/ls.html on the search for right option.

I found "-n, --numeric-uid-gid List numeric UIDs and GIDs instead of
names" - but that's for the uid and gid but not for the file permissions.

But "-?, --numeric-* List numeric permissions instead of symbolic" is
nowhere to be see.

Could it really be that there is no such option?

Martin

PS I have both Solaris ls and an up-to-date self compiled GNU ls available.
--
mailto://kris...@users.sourceforge.net
Ada programming at: http://ada.krischik.com

Stephane Chazelas

unread,
Feb 12, 2008, 7:41:57 AM2/12/08
to
On Tue, 12 Feb 2008 13:27:49 +0100, Martin Krischik wrote:
[...]

> Currently I am trying to create some Solaris installations packages and
> to do so I need the know the current file permissions for "/etc/env".
>
> I thought "ls -l -d -? /etc/env'" with '-?' being an option I don't know
> yet and which will change the display format from "drwxrwxrwt" to octal.
>
> Now I read "ls --help", "man ls", "info ls", Wikipedia and
> http://www.linux-command.com/ls.html on the search for right option.
>
> I found "-n, --numeric-uid-gid List numeric UIDs and GIDs instead of
> names" - but that's for the uid and gid but not for the file permissions.
>
> But "-?, --numeric-* List numeric permissions instead of symbolic" is
> nowhere to be see.
>
> Could it really be that there is no such option?
[...]

I'm afraid there is no standard command to retrieve the file
permissions in octal.

You can convert the rw-r--r-- to octal with something like:

ls -ld FILENAME | sed 's/.\(.........\).*/\1/
h;y/rwsxtST-/IIIIIOOO/;x;s/..\(.\)..\(.\)..\(.\)/|\1\2\3/
y/sStTx-/IIIIOO/;G
s/\n\(.*\)/\1;OOO0OOI1OIO2OII3IOO4IOI5IIO6III7/;:k
s/|\(...\)\(.*;.*\1\(.\)\)/\3|\2/;tk
s/^0*\(..*\)|.*/\1/;q'

You could use GNU find:

find FILENAME -prune -printf '%m\n'

or GNU stat:

stat -c %a FILENAME

or zsh stat:

zstat -o +mode FILENAME
(also includes the file type)

--
Stephane

Martin Krischik

unread,
Feb 12, 2008, 8:12:17 AM2/12/08
to
Stephane Chazelas schrieb:

> On Tue, 12 Feb 2008 13:27:49 +0100, Martin Krischik wrote:
> [...]
>> Currently I am trying to create some Solaris installations packages and
>> to do so I need the know the current file permissions for "/etc/env".
> [...]

>> But "-?, --numeric-* List numeric permissions instead of symbolic" is
>> nowhere to be see.
>>
>> Could it really be that there is no such option?
> [...]
>
> I'm afraid there is no standard command to retrieve the file
> permissions in octal.

The original Unix designers where so keen on octal number so this
surprises me big time.

> You can convert the rw-r--r-- to octal with something like:

I tried the all - but they will only display 3 digit permissions. Well
for Solaris

pkgproto FILENAME

will do the trick.

Martin

John W. Krahn

unread,
Feb 12, 2008, 11:16:20 AM2/12/08
to
Martin Krischik wrote:
>
> Currently I am trying to create some Solaris installations packages and
> to do so I need the know the current file permissions for "/etc/env".
>
> I thought "ls -l -d -? /etc/env'" with '-?' being an option I don't know
> yet and which will change the display format from "drwxrwxrwt" to octal.
>
> Now I read "ls --help", "man ls", "info ls", Wikipedia and
> http://www.linux-command.com/ls.html on the search for right option.
>
> I found "-n, --numeric-uid-gid List numeric UIDs and GIDs instead of
> names" - but that's for the uid and gid but not for the file permissions.
>
> But "-?, --numeric-* List numeric permissions instead of symbolic" is
> nowhere to be see.
>
> Could it really be that there is no such option?

$ perl -e'printf "%o\n", ( stat "/etc" )[ 2 ]'
40755


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Icarus Sparry

unread,
Feb 12, 2008, 12:06:39 PM2/12/08
to
On Tue, 12 Feb 2008 13:27:49 +0100, Martin Krischik wrote:

The "ls" from the ast-open toolkit allows you to get this information, use

ls --format='%(perm)o' filename

to get the value in octal, or

ls --format='%(perm)d' filename

to get the value in decimal. AST-open is available free under an
opensource license. Probably the most common reason for getting it is the
version of ksh93 by the original author.

http://www.research.att.com/sw/download/

Maxwell Lol

unread,
Feb 13, 2008, 1:10:42 PM2/13/08
to
Martin Krischik <kris...@users.sourceforge.net> writes:


>Could it really be that there is no such option?

SunOS and AT&T created a merged BSD/SysV Unix in 1987, when they
"standardized" all of the unix command line arguments.

Linux was started in 1991.

It's easy to convert the drwxrwxrwx string into octal. See Stephanee's
post. Perhaps that's why it wasn't added.

In those days, many people didn't like unnecessary "extras" in basic
commands. See Rob Pike's "UNIX Style, or cat -v Considered Harmful"

Quote:

"We are reminded that ls isn't the place for code to break a
single column into multiple ones"


Barry Margolin

unread,
Feb 13, 2008, 6:21:57 PM2/13/08
to
In article <86r6fgi...@localhost.localdomain>,
Maxwell Lol <nos...@com.invalid> wrote:

> Martin Krischik <kris...@users.sourceforge.net> writes:
>
>
> >Could it really be that there is no such option?
>
> SunOS and AT&T created a merged BSD/SysV Unix in 1987, when they
> "standardized" all of the unix command line arguments.
>
> Linux was started in 1991.
>
> It's easy to convert the drwxrwxrwx string into octal. See Stephanee's
> post. Perhaps that's why it wasn't added.
>
> In those days, many people didn't like unnecessary "extras" in basic
> commands. See Rob Pike's "UNIX Style, or cat -v Considered Harmful"

But wouldn't the translation from octal into rwx notation be considered
more of an "extra"?

I've also been surprised for several decades that this doesn't exist.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Maxwell Lol

unread,
Feb 13, 2008, 7:58:43 PM2/13/08
to
Barry Margolin <bar...@alum.mit.edu> writes:

> > In those days, many people didn't like unnecessary "extras" in basic
> > commands. See Rob Pike's "UNIX Style, or cat -v Considered Harmful"
>
> But wouldn't the translation from octal into rwx notation be considered
> more of an "extra"?

Heh. heh. Perhaps.
But it does eliminate the question "which is write? 2 or 4?" :-)

Stephane Chazelas

unread,
Feb 14, 2008, 2:53:41 AM2/14/08
to
On 12 Feb 2008 12:41:57 GMT, Stephane Chazelas wrote:
> On Tue, 12 Feb 2008 13:27:49 +0100, Martin Krischik wrote:
> [...]
>> Currently I am trying to create some Solaris installations packages and
>> to do so I need the know the current file permissions for "/etc/env".
>>
>> I thought "ls -l -d -? /etc/env'" with '-?' being an option I don't know
>> yet and which will change the display format from "drwxrwxrwt" to octal.
>>
>> Now I read "ls --help", "man ls", "info ls", Wikipedia and
>> http://www.linux-command.com/ls.html on the search for right option.
>>
>> I found "-n, --numeric-uid-gid List numeric UIDs and GIDs instead of
>> names" - but that's for the uid and gid but not for the file permissions.
>>
>> But "-?, --numeric-* List numeric permissions instead of symbolic" is
>> nowhere to be see.
>>
>> Could it really be that there is no such option?
> [...]
>
> I'm afraid there is no standard command to retrieve the file
> permissions in octal.
[...]

Actually, there is one:

pax -w filename |
dd ibs=1 skip=103 count=4 2> /dev/null

Or better, to allow longer file names:

pax -x cpio -w filename |
dd ibs=1 skip=20 count=4 2> /dev/null

--
Stephane

denis....@gmail.com

unread,
Feb 28, 2008, 9:30:17 AM2/28/08
to
Depending on which version of shell/unix you have, I was looking for
the same solution as you and I think I've found exactly what I need :

stat --format=%a,%U,%G,%t,%n /etc/*

Denis

Have a nice day !

On 12 fév, 13:27, Martin Krischik <krisc...@users.sourceforge.net>
wrote:


> Hello
>
> Currently I am trying to create some Solaris installations packages and
> to do so I need the know the current file permissions for "/etc/env".
>
> I thought "ls -l -d -? /etc/env'" with '-?' being an option I don't know
> yet and which will change the display format from "drwxrwxrwt" to octal.
>

> Now I read "ls --help", "man ls", "info ls", Wikipedia andhttp://www.linux-command.com/ls.htmlon the search for right option.


>
> I found "-n, --numeric-uid-gid List numeric UIDs and GIDs instead of
> names" - but that's for the uid and gid but not for the file permissions.
>
> But "-?, --numeric-* List numeric permissions instead of symbolic" is
> nowhere to be see.
>
> Could it really be that there is no such option?
>
> Martin
>
> PS I have both Solaris ls and an up-to-date self compiled GNU ls available.
> --

> mailto://krisc...@users.sourceforge.net

Lowe Schmidt

unread,
Mar 11, 2008, 5:31:09 AM3/11/08
to
On Feb 13, 7:10 pm, Maxwell Lol <nos...@com.invalid> wrote:

> Martin Krischik <krisc...@users.sourceforge.net> writes:
> >Could it really be that there is no such option?
>
> SunOS and AT&T created a merged BSD/SysV Unix in 1987, when they
> "standardized" all of the unix command line arguments.
>
> Linux was started in 1991.
But 'ls' was written by GNU so that's sometime in the early to mid
80's...

Maxwell Lol

unread,
Mar 11, 2008, 8:06:12 PM3/11/08
to
Lowe Schmidt <lowe.s...@gmail.com> writes:

> On Feb 13, 7:10 pm, Maxwell Lol <nos...@com.invalid> wrote:
> > Martin Krischik <krisc...@users.sourceforge.net> writes:
> > >Could it really be that there is no such option?
> >
> > SunOS and AT&T created a merged BSD/SysV Unix in 1987, when they
> > "standardized" all of the unix command line arguments.
> >
> > Linux was started in 1991.
> But 'ls' was written by GNU so that's sometime in the early to mid
> 80's...

According to coreutils-5.0/old/fileutils
The code to replace 'ls' was started 1997, not 1980's.

Stephane CHAZELAS

unread,
Mar 11, 2008, 8:20:57 PM3/11/08
to
2008-03-11, 20:06(-04), Maxwell Lol:
[...]

>> > Linux was started in 1991.
>> But 'ls' was written by GNU so that's sometime in the early to mid
>> 80's...
>
> According to coreutils-5.0/old/fileutils
> The code to replace 'ls' was started 1997, not 1980's.
[...]

Are you trying to say that Linux systems before 1997 didn't have
ls?

From ftp.gnu.org/old-gnu, GNU textutils-1.0 in 1990 had ls already.

--
Stéphane

Maxwell Lol

unread,
Mar 12, 2008, 10:02:58 AM3/12/08
to
Stephane CHAZELAS <this.a...@is.invalid> writes:

> 2008-03-11, 20:06(-04), Maxwell Lol:
> [...]
> >> > Linux was started in 1991.
> >> But 'ls' was written by GNU so that's sometime in the early to mid
> >> 80's...
> >
> > According to coreutils-5.0/old/fileutils
> > The code to replace 'ls' was started 1997, not 1980's.
>

> Are you trying to say that Linux systems before 1997 didn't have
> ls?
>
> From ftp.gnu.org/old-gnu, GNU textutils-1.0 in 1990 had ls already.

Thanks for the reference. Lowe Schmidt says that gnu ls was developed
in 'early to mid 80's...', and I am not able to verify this.

Carl Lowenstein

unread,
Mar 12, 2008, 11:54:39 PM3/12/08
to
In article <86abl4c...@localhost.localdomain>,

You all must realize that there was Unix long before GNU or Linux.
Unix ls(1) has been around for quite a while. It is documented in 6th
Edition Unix with date 3/20/74. That's 1974-03-20 in translation.

It too interprets mode bits as rwx not 421.

carl

--
carl lowenstein marine physical lab, u.c. san diego
clowe...@ucsd.edu

Stephane CHAZELAS

unread,
Mar 13, 2008, 4:21:18 AM3/13/08
to
2008-03-13, 03:54(+00), Carl Lowenstein:
[...]

> You all must realize that there was Unix long before GNU or Linux.
[...]

I don't think anyone knowing what GNU stands for doubts that.
Unix started in the late 60s, GNU in 1983.

> Unix ls(1) has been around for quite a while. It is documented in 6th
> Edition Unix with date 3/20/74. That's 1974-03-20 in translation.

[...]

If you're interested in Unix history, you can have a look at
www.tuhs.org where you can find for instance the man page for
Unix V3 ls.

I'd be interested on where to find old code archives for GNU.

IIRC, circa 1995, on Linux, there were several different
implementations of ls available. If my memory serves me right,
the default one on slackware didn't have colour support so it's
possible that it wasn't the GNU one.

--
Stéphane

pk

unread,
Mar 13, 2008, 4:39:14 AM3/13/08
to
Stephane CHAZELAS wrote:

> I'd be interested on where to find old code archives for GNU.

You probably already know

ftp://ftp.gnu.org/old-gnu

, don't you?

Stephane CHAZELAS

unread,
Mar 13, 2008, 4:53:42 AM3/13/08
to
2008-03-13, 09:39(+01), pk:

Well yes since I'm the one who brought it up in this thread, but
what about versions of fileutils prior to 3.13 for instance? Or
even prior to 1.0?

--
Stéphane

pk

unread,
Mar 13, 2008, 8:54:07 AM3/13/08
to
Stephane CHAZELAS wrote:

>> You probably already know
>>
>> ftp://ftp.gnu.org/old-gnu
>>
>> , don't you?
>
> Well yes since I'm the one who brought it up in this thread,

Ah erm...well...yes. I didn't read the thread very carefully :-)

> but what about versions of fileutils prior to 3.13 for instance? Or
> even prior to 1.0?

Actually, a bit of googling reveals no traces of those older versions. It
seems that they're actually really hard to find.
If you are content with binaries, then probably some old distro (perhaps to
be run in a virtual machine) for instance among those at

http://www.ibiblio.org/pub/historic-linux

/might/ provide older versions of GNU tools.

0 new messages