INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

file modes: convert from "text" to octal

file modes: convert from "text" to octal

(OP)
hello,
my current solution bases on a map file (generated maybe not in "elegant" way)...

CODE

# a=0 b=0 c=0 d=0;until [ $a -eq 8 ];do until [ $b -eq 8 ]; do until [ $c -eq 8 ];do until [ $d -eq 8 ];do touch ${a}${b}${c}${d};chmod ${a}${b}${c}${d} ${a}${b}${c}${d};ls -ld ${a}${b}${c}${d}|awk '{print $1,$NF}';rm ${a}${b}${c}${d};((d+=1));done;d=0;((c+=1));done;c=0;((b+=1));done;b=0;((a+=1));done >mapa.permissionow
# wc mapa.permissionow
    4096    8192   65536 mapa.permissionow
# ls -ld /tmp
drwxrwxrwt   14 bin      bin           20480 Feb 14 16:25 /tmp
# grep ^.rwxrwxrwt mapa.permissionow|cut -d" " -f2
1777
# 

and I am looking for something quicker or more natural way to check it in a UNIX directly on file, - a command which can return file modes in octal instead of .rwx..... form

regards

RE: file modes: convert from "text" to octal

(OP)
thx. it was helpful - result:

CODE

pperm () { perl -e '$mode = (stat("$ARGV[0]"))[2]; printf("%04o",$mode & 07777 );' $1; } 

I also found another solution/script on a web:

CODE

#!/usr/bin/ksh

ls -ld $1 | 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' 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close