Viewing your folder and files permission Numerically

Have you ever been wondering if you could only view the folders and files permission same way like you what are doing in chmod command?


To tell you honest, I am not a good reader for this kind of format:

7 = 4+2+1 (read/write/execute)
6 = 4+2 (read/write)
5 = 4+1 (read/execute)
4 = 4 (read)
3 = 2+1 (write/execute)
2 = 2 (write)
1 = 1 (execute)


So I keep on searching on the web and let me share with you what I learned and found out. This procedure helps me a lot and save my day.

So let us get started.

Open your gedit and paste the code below:


#!/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

Now your done. Save it as "showperm.sh" without quotes of course in safe place such as /home/[yourusername]/Documents/

Next we will create symbolic link so where ever you are in your folders, you can call it.

Open your Terminal ( ctrl + alt + t ). Go to: /usr/local/bin

I assume now your are in the bin directory. Now type this and modify the text you should alter as based on your system setup:

Syntax:
--------

ln -s [where your file reside] [where to put it]

Actual code using our example file name and folder structure:

ln -s /home/mark/Documents/showperm.sh /usr/local/bin/showperm

OR if you don't want it to rename and you are in bin folder

ln -s /home/mark/Documents/showperm.sh .

Once done. Your good to go.

In your Terminal, do this:

showperm /home/mark/

And the expected output:

755  2 mark mark 4.0K Oct  3 17:13 Desktop/
755 10 mark mark 4.0K Oct  3 08:11 Documents/
755 23 mark mark  16K Oct  3 17:13 Downloads/
755  2 mark mark 4.0K Sep 20 09:15 Music/
755  2 mark mark 4.0K Sep 23 10:06 Pictures/
755  5 mark mark 4.0K Sep 29 11:19 Videos/

Now see the most left? It is now 755 instead of seeing drwxr-xr-x

Hope you enjoy and please feel free to comment below.

Cheers!

View folder and files permission numerically

Posted on

Friday, October 4, 2013

Leave a Reply

I love comments hopefully you can put one.