- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Numeric file permissions?
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
Forums
Discussions
Discussions
Discussions
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
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
01-21-2003 03:40 PM
01-21-2003 03:40 PM
Is there an easy way to display the permissions of a file in numeric format like "775"?
Thanks,
Kris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2003 03:43 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2003 04:46 PM
01-21-2003 04:46 PM
Re: Numeric file permissions?
I tried to write a script in shell just for sake of it and ofcourse for my fun. I made it bit eloborate so that I wouldn't get confused myself while writing it. This lists the permissions in four digit format. For ex., 4555 or 0555 so that you would know if the file has suid/sgid/sticky bits.
Call it get_perms.ksh and run it with
---start---
#!/usr/bin/ksh
if [ $# -ne 1 ]
then
echo "Usage: $0 file"
exit
fi
PERM=$(ll $1|sed 's/-/0/g'| awk '{print $1}')
A=0
B=$(echo $PERM|cut -c 4)
if [[ "$B" = "s" || "$B" = "S" ]]
then
(( A = $A + 4 ))
fi
C=$(echo $PERM|cut -c 7)
if [[ "$C" = "s" || "$C" = "S" ]]
then
(( A = $A + 2 ))
fi
D=$(echo $PERM|cut -c 10)
if [[ "$C" = "t" || "$C" = "T" ]]
then
(( A = $A + 1 ))
fi
PERM=$(echo $PERM|sed -e 's/r/4/g' -e 's/w/2/g' -e 's/x/1/g' -e 's/s/1/g' -e 's/
t/1/g' -e 's/S/0/g' -e 's/T/0/g')
printf "$A"
printit()
{
c=0
K=$1
for i in $K
do
VAL=$(echo $PERM|cut -c $i)
((c = $c + $VAL ))
done
printf "$c"
}
printit "2 3 4"
printit "5 6 7"
printit "8 9 10 "
printf " $1\n"
---End--
-Sri
PS: Becareful while cutting pasting the sed statement. It should be in one line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2003 04:51 AM
01-22-2003 04:51 AM
Re: Numeric file permissions?
No argument that perl is shorter/faster here, but here's another shell solution I offered sometime ago when this question was asked:
The script returns the octal numeric mode of the file passed to it. The script handles the setuid, setgid and sticky bits in addition to the standard permissions:
#!/usr/bin/sh
#
typeset -i PERMFCT=0 #...permission mode factor
typeset -i MISCFCT=0 #...miscellaneous mode factor
typeset -i BITSNBR=2 #...bit number (1-relative)
typeset -i BITSVAL=0 #...simple bit value
typeset -i OCTMODE=0 #...final, octal numeric mode
#
[ "$#" != 1 ] && { echo "Usage: $0 file"; exit 1 ; }
#
SMODE=`ls -l $1|awk '{print $1}`
#
while (( BITSNBR <= 10 ))
do
case `expr \( $BITSNBR - 2 \) / 3` in #...establish weighted values...
0 )
PERMFCT=100
MISCFCT=4000
;;
1 )
PERMFCT=10
MISCFCT=2000
;;
2 )
PERMFCT=1
MISCFCT=1000
;;
esac
#
case `expr substr $SMODE $BITSNBR 1` in
r )
BITSVAL=4
MISCFCT=0
;;
w )
BITSVAL=2
MISCFCT=0
;;
x )
BITSVAL=1
MISCFCT=0
;;
s|t )
BITSVAL=1
;;
S|T )
BITSVAL=0
;;
* )
BITSVAL=0
MISCFCT=0
;;
esac
#
OCTMODE=`expr $PERMFCT \* $BITSVAL + $MISCFCT + $OCTMODE`
#
let BITSNBR=$BITSNBR+1
done
#
echo "mode = $OCTMODE"
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2003 09:53 AM
01-22-2003 09:53 AM
Re: Numeric file permissions?
I decided to use A. Clay's method. It was was much easier.
Thanks to everybody,
Kris