Operating System - HP-UX
1833606 Members
3314 Online
110061 Solutions
New Discussion

how to display file permission

 
Ridzuan Zakaria
Frequent Advisor

how to display file permission

Hi,

How do I display file permission in numeric instead of characters.

example:
From:
-rwxr-xr-x 1 oracle dba 3554 Dec 20 13:53 DataRefresh.sh

To:
755 1 oracle dba 3554 Dec 20 13:53 DataRefresh.sh

Thanks.


quest for perfections
6 REPLIES 6
Sanjay_6
Honored Contributor

Re: how to display file permission

Hi,

you cannot do that. the rwx is the standard naming convention.

You can always put a wrapper around the ls command, but i do not think that would be a recommended choice.

Hope this helps.

Regds
Bill Hassell
Honored Contributor

Re: how to display file permission

There is no option to display the octal equivalent of the permission settings. Several people have written scripts to display the numeric value. Attached is a simple function that takes the permission string and echoes back the numeric equivalent, suitable for chmod.


Bill Hassell, sysadmin
A. Clay Stephenson
Acclaimed Contributor

Re: how to display file permission

This is one of the tasks that Perl makes very easy:

fmode.pl
----------------------------

#!/usr/bin/perl -w

use strict;
my $i = 0;
my $cc = 0;
while ($i <= $#ARGV && $cc == 0)
{
if (-e $ARGV[$i])
{
my $mode = (stat($ARGV[$i]))[2];
printf("%s\t%03o\n",$ARGV[$i],$mode & 777);
}
else
{
printf STDERR ("File '%s' not found.\n",$ARGV[$i]);
$cc = 2;
}
++$i;
}
exit($cc);

------------------------------------

Use it like this:

fmode.pl myfile myfile2
If it ain't broke, I can fix that.
B. Hulst
Trusted Contributor

Re: how to display file permission

And from the perl command you make an alias so you only have to type ll or lll.

alias lll='fmode.pl'

The command lll will give you the numbers. :-)

- Bob

Ps. I don't know if the sticky bits will be translated correctly with that perl script. ;-)
Jack C. Mahaffey
Super Advisor

Re: how to display file permission

I've attached a script that I posted on this site awhile back. Come's in very useful. I use it all the time.

Here's an example for using it:

# getchmod /etc/group
0444 -r--r--r-- file bin:bin /etc/group
B. Hulst
Trusted Contributor

Re: how to display file permission

The latter script will handle all the file protection settings. Cool :-)