ls to show numeric permission bit ...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers ls to show numeric permission bit ...
# 1  
Old 07-19-2010
ls to show numeric permission bit ...

Hi all,

Is there an option in ls that will show the permission bit in numbers instead of the permissions?

The ls output below are very useful I guess, but I want to know if it is possible to run ls where it just shows 600 I guess which is the numeric equivalent of the permission bit of the file. Basically, am looking for something similar to the Linux's stat -c "%a %n" testfile. Unfortunately, stat is not available in Solaris.

BTW, the output from ls -v, why does the group has #effective label, what does that mean? Can't understand what the output from ls -v means, I've already check on the man pages and still don't understand it, anyone who can give a better explanation about what the output from ls -v means, mainly on the line 2:mask:rwx, the other lines, I can "guess" what they means ... Smilie

Thanks in advance.

Code:
$ ls -v testfile
-rw-------   1 root     root           0 Jul 19 13:31 testfile
     0:user::rw-
     1:group::---               #effective:---
     2:mask:rwx
     3:other:---
$ ls -e testfile
-rw-------   1 root     root           0 Jul 19 13:31:36 2010 testfile
$ ls -l testfile
-rw-------   1 root     root           0 Jul 19 13:31 testfile


Last edited by newbie_01; 07-19-2010 at 02:43 AM.. Reason: More information
# 2  
Old 07-19-2010
AFAIK, ls cannot show numeric permission bits.

But, you can write a simple script which can read and convert this rwx to appropriate numeric bits and make it to show to you.
# 3  
Old 07-19-2010
You can use Perl:

Code:
perl -le'
  printf "%s is mode %o\n", $_, 07777 & (stat)[2] 
    for @ARGV
    ' *

As far as the ACLs are concerned:

Quote:
The user and group permissions are those for the owner (user) and the default group (prof), respectively. The mask indicates the maximum permission available to all users, except the owner. The effective permission, to the right of the group permission, represents the intersection (bitwise AND) of the specified permissions for a user/group and the mask field. The effective permission is what a user, other than the owner, will see when they try to access the file
The quote is from this url.

Last edited by radoulov; 07-19-2010 at 04:55 AM..
# 4  
Old 07-19-2010
Code:
#!/bin/bash

ls -lhF $1 | while read DATA
do
  case "${DATA:0:1}" in
  "-"|"d")
    PERM=$( echo "${DATA:1:9}" | sed 's/-/0/g;s/r/4/g;s/w/2/g;s/x/1/g' )
    P_US=$((${PERM:0:1}+${PERM:1:1}+${PERM:2:1}))
    P_GR=$((${PERM:3:1}+${PERM:4:1}+${PERM:5:1}))
    P_OT=$((${PERM:6:1}+${PERM:7:1}+${PERM:8:1}))
    DATA=$( echo "$DATA" | sed "s/${DATA:0:10}/${P_US}${P_GR}${P_OT}/" )
    echo "$DATA"
  ;;
  *)
    continue
  ;;
  esac
done

exit 0
#finis

Code:
[house@leonov] ll .
total 8.0K
-rw-r--r-- 1 house house 450 19. Jul 11:32 code
[house@leonov] bash code .
644 1 house house 450 19. Jul 11:32 code
[house@leonov] ll ..
total 798K
-rw-r--r--  1 house house 534K 14. Jul 10:31 bootchart_long.jpg
-rw-r--r--  1 house house 219K 14. Jul 10:31 bootchart_short.jpg
-rwxr-xr-x  1 house house 4.3K 14. Mai 17:28 chromify
drwxr-xr-x 16 house house  648 18. Jul 11:45 Labour/
drwxr-xr-x  2 house house  208  1. Mai 17:04 Mahab/
drwxr-xr-x  8 house house  368 12. Mai 12:00 Scratch/
[house@leonov] bash code ..
644  1 house house 534K 14. Jul 10:31 bootchart_long.jpg
644  1 house house 219K 14. Jul 10:31 bootchart_short.jpg
755  1 house house 4.3K 14. Mai 17:28 chromify*
755 16 house house  648 18. Jul 11:45 Labour/
755  2 house house  208  1. Mai 17:04 Mahab/
755  8 house house  368 12. Mai 12:00 Scratch/

# 5  
Old 07-20-2010
Quote:
Originally Posted by radoulov
You can use Perl:

Code:
perl -le'
  printf "%s is mode %o\n", $_, 07777 & (stat)[2] 
    for @ARGV
    ' *

But, why I am getting result 420 for the below command?
Code:
perl -le 'print (07777 & (stat("./file.txt"))[2])'

The expected answer is 644
# 6  
Old 07-20-2010
Quote:
Originally Posted by royalibrahim
But, why I am getting result 420 for the below command?
Code:
perl -le 'print (07777 & (stat("./file.txt"))[2])'

The expected answer is 644
Hi.

You're displaying the result in decimal. It should be in octal (%o)

Code:
$ printf "%o\n" 420
644


Last edited by Scott; 07-20-2010 at 02:35 AM..
This User Gave Thanks to Scott For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Which version of Windows Vista to install with a product key? 32-bit or 64-bit?

Hello everyone. I bought a dell laptop (XPS M1330) online which came without a hard drive. There is a Windows Vista Ultimate OEMAct sticker with product key at the bottom case. I checked dell website (here) for this model and it says this model supports both 32 and 64-bit version of Windows... (4 Replies)
Discussion started by: milhan
4 Replies

2. Shell Programming and Scripting

How to handle 64 bit arithmetic operation at 32 bit compiled perl interpreter?H

Hi, Here is the issue. From the program snippet I have Base: 0x1800000000, Size: 0x3FFE7FFFFFFFF which are of 40 and 56 bits. SO I used use bignum to do the math but summing them up I always failed having correct result. perl interpreter info, perl, v5.8.8 built for... (0 Replies)
Discussion started by: rrd1986
0 Replies

3. Shell Programming and Scripting

SFTP show Permission is denied

Hi. I am running this line in AIX unix and I am getting the error Permission is denied. Could you help me on this please. rcp -p rgranado@sniux01:/homeusr/ven/edi/procesados/asn/* gisadm@sniux03:/gentran/SI51/install/HD_XML/OUT Please use next time code tags for your code and data (2 Replies)
Discussion started by: cucosss
2 Replies

4. Shell Programming and Scripting

Permission bit translator - octal to textual and vice versa

Hi, Does anyone know of any permission bit "translator"? One that can translate the permission bit from its textual value to its octal value and vice versa. It is alright if it is always just rwx but on a lot of occasions nowadays, getting a lots of s, S, t, etc. -rwxrwxrwx 1 oracle dba... (4 Replies)
Discussion started by: newbie_01
4 Replies

5. UNIX for Dummies Questions & Answers

Find and Replace random numeric value with non-numeric value

Can someone tell me how to change the first column in a very large 17k line file from a random 10 digit numeric value to a non numeric value. The format of lines in the file is: 1702938475,SNU022,201004 the first 10 numbers always begin with 170 (6 Replies)
Discussion started by: Bahf1s
6 Replies

6. Shell Programming and Scripting

Permission bit calculator ???

Hi, Does anyone have a UNIX permission bit calculator script that I can use? Basically, am looking for one where I don't have to a ls -l to check the permission on a file or directory. Am looking for a script that will display the permission bits and then just display what those permission... (1 Reply)
Discussion started by: newbie_01
1 Replies

7. Shell Programming and Scripting

Perl code to differentiate numeric and non-numeric input

Hi All, Is there any code in Perl which can differentiate between numeric and non-numeric input? (11 Replies)
Discussion started by: Raynon
11 Replies

8. Programming

copying or concatinating string from 1st bit, leaving 0th bit

Hello, If i have 2 strings str1 and str2, i would like to copy/concatenate str2 to str1, from 1st bit leaving the 0th bit. How do i do it? (2 Replies)
Discussion started by: jazz
2 Replies
Login or Register to Ask a Question