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.

Students Click Here

ls and chmod commands

ls and chmod commands

ls and chmod commands


When I do a ls -l, I can see my directories have
drwxr-xr-xr. I am more used to the chmod numerical syntax like 755.  Is there an easy way to list out the numerical permissions rather than rwx etc.

RE: ls and chmod commands

The only trick i can give you is :

relpace rwx by 421 (r=4, w=2 and x=1) and add it up

rwxr-xr-x would mean 4214-14-1 = (4+2+1) (4+1) (4+1) = 755

As for ls , i don't think it's feasable.


RE: ls and chmod commands

following shell/awk script may be of use to you:


# # # # #
# if -l or -U or -e is specified,
#  perform real ls and awk output to convert -rwxrwxrwx to numeric form
# if no long listing,
#  just perform the real ls
for parameter
 case ${parameter} in
if [ "${longlist}" = 'yes' ]
 /usr/bin/ls $*|awk '{
 # # #
 # look for the field containing permission bits
 for (i=1;i<=NF;i++) {
  if ($i ~ /^[bcdlps-][r-][w-][xsS-][r-][w-][xsS-][r-][w-][xtT-][E+-]*/) {
   # # #
   # break up into individual bits
   ur=substr($i,2,1); uw=substr($i,3,1); ux=substr($i,4,1);
   gr=substr($i,5,1); gw=substr($i,6,1); gx=substr($i,7,1);
   or=substr($i,8,1); ow=substr($i,9,1); ox=substr($i,10,1);
   # # #
   # substitute type and extended attributes flags if necessary
   if (tp=="-") tp=" ";
   if (ea=="-") ea=" ";   if (ea=="") ea=" ";
   # # #
   # convert to numeric representation
   if (ur=="r") num+=400; if (uw=="w") num+=200;
   if (ux=="x") num+=100; if (ux=="s") num+=4100; if (ux=="S") num+=4000;
   if (gr=="r") num+=40;  if (gw=="w") num+=20;
   if (gx=="x") num+=10;  if (gx=="s") num+=2010; if (gx=="S") num+=2000;
   if (or=="r") num+=4;   if (ow=="w") num+=2;
   if (ox=="x") num+=1;   if (ox=="t") num+=1001; if (ox=="T") num+=1000;
   # # #
   # print out type of file, numeric representation
   # and possibly the extended attributes indication
   printf "%s%04d%s ", tp, num, ea;
   # # #
   # found the permissions field, no need to continue searching
 # # #
 # print out original line
 # no longlist
 /usr/bin/ls $*

If you name this script /usr/local/bin/numls, chmod 755 it and use an alias ls=numls, then you can just use 'ls -whatever whichever' and get the modified output from the script, provided of course /usr/local/bin is in your search PATH.



RE: ls and chmod commands

A star for that p5wizard!

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! Already a Member? Login

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