- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Numeric file modes
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2002 11:25 AM
тАО06-10-2002 11:25 AM
A friend suggested that I ask you guys. Is there an easy way to get a file's permission in numeric form rather than rw-rw-rw-?
I am trying to use a case inside a script and the symbolic forms are such a pain. Anybody know an easy method?
Thanks, Kris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2002 11:30 AM
тАО06-10-2002 11:30 AM
SolutionCan you say 'Perl'?
Try this 60-second quickie:
#!/usr/bin/perl -w
use strict;
my $i = 0;
while ($i <= $#ARGV)
{
my $mode = (stat($ARGV[$i]))[2];
printf("%s\t%03o\n",$ARGV[$i],$mode & 0777);
++$i;
}
That should do it. We are taking a slice (the 3rd element) from the stat function.
For each argument on the command line, you get a filename and the octal permissions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2002 11:33 AM
тАО06-10-2002 11:33 AM
Re: Numeric file modes
perl -e '$file=
Run this and enter in the filename and it will display in octal the permissions.
I wrote this so it could be used as a filter program.
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2002 11:35 AM
тАО06-10-2002 11:35 AM
Re: Numeric file modes
use File::Find;
{
$filename = $ARGV[0];
finddepth(\&wanted,"$filename");
}
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
if ((($f_dev,$f_ino,$f_mode,$f_nlink,$f_uid,$f_gid,$f_rdev,$f_size,$f_at
ime,$f_mtime,$f_ctime,$f_blksize,$f_blocks) = lstat($_))) {
$f_filetype = substr(sprintf("%6.6o",$f_mode),0,2);
$f_filemode = substr(sprintf("%6.6o",$f_mode),2,4);
printf("%d:%s:%s:%d:%d:%d:%d:%d:%d:%d:%d:%d:%s\n",$f_ino,$f_filetype,
$f_filemode,$f_uid,$f_gid,$f_rdev,$f_size,$f_atime,$f_mtime,$f_ctime,$f_blksize,
$f_blocks,$File::Find::name);
}
}
from http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xcf7650011d20d6118ff40090279cd0f9,00.html
+mode +wanted
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2002 12:04 PM
тАО06-10-2002 12:04 PM
Re: Numeric file modes
I used Clay's answer because it displayed just what I needed. Rodney's solution displays 6 digits and I only wanted the last 3 digits. Harry's was more than I needed.
Thanks very much, Kris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2002 12:25 PM
тАО06-10-2002 12:25 PM
Re: Numeric file modes
:-)
Marty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2002 02:05 PM
тАО06-11-2002 02:05 PM
Re: Numeric file modes
I need help with a small change. I would really like this to print separate digits for "owner","group", and "other". If I do this command "perms user1.dat", the script displays "user1.dat 664". I would like it to display "user1.dat 6 6 4". I know I could do this with cut but I would rather do this directly in the perms perl program because I need to process thousands of files. This is probably easy for a perl programmer but I can't seem to get it to work. Please help.
Thanks, Kris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2002 02:15 PM
тАО06-11-2002 02:15 PM
Re: Numeric file modes
I assume that you are probably doing something like this in the shell in some sort of loop:
echo "${FNAME}" | perms.pl read FILENAME OWNER GROUP OTHER
You would like for me to make life easier for you. Well, it is simple:
Change:
printf("%s\t%03o\n",$ARGV[$i],$mode & 0777);
To:
printf("%s\t%o\t%o\t%o\n",
$ARGV[$i],($mode & 0700) >> 6,
($mode & 070) >> 3,($mode & 07));
The >> 6 bit-shifts the operand 6 bits (2 octal digits) to the right. I could have divided by 0100 but the bit-shift is more elegant, don't you think?
If I haven't made a typo, that should fix you. I left
P.S. O'reilly has some excellent Perl books. Look for the ones with camels on the cover.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2002 02:30 PM
тАО06-11-2002 02:30 PM
Re: Numeric file modes
printf("%s\t%03o\n",$ARGV[$i],$mode & 0777);
to
@x=split(//,sprintf("%03",$mode & 0777));
printf "%s\t%s\n",$ARGV[$i],join(" ",@x);
-- Rod Hills