Chmod calculator

chmod is a UNIX®/Linux® command that lets the owner/administrator of a file to specify how much/little access should be permitted to it. File permissions in UNIX®/Linux® file system are managed in three distinct user classes: user/owner, group and others. Each class can have read, write and execute permissions. File permission can be represented in a symbolic or numeric (octal) format.

Mapping of file permissions to symbol and numeric format is summarized in the table below:

File Permission Symbolic Format Numeric Format
no permission --- 0
execute --x 1
write -w- 2
write and execute -wx 3
read r-- 4
read and execute r-x 5
read and write rw- 6
read,write and execute rwx 7

A symbolic notation, -rwxr-xr-x: represents a regular file with full permissions for user class and read/execute permission for group and others classes. Corresponding octal notation for the file permission is 755.

For more details refer to “chmod” command help.

Chmod calculator is a utility that can be used to calculate the numeric value for a desired set of file permissions in UNIX/LINUX file system. This is a very useful utility for students, developers and system administrators.

Code snippet for calculating the chmod numeric value:

/**
 * Calculate the numeric value for chmod based on checkbox state
 * @param group : User class name [owner, group, other]
 * @param no    : Octal number for read/write/execute permission
 * @param chkBox: CheckBox element
 */

function calculate(group, no, chkBox) {
      var r = 4;
      var w = 2;
      var x = 1;
      //Get the numeric value for provided user class
      var total = "total_" + group;
      var num = document.getElementById(total).value;
      var number = parseInt(num, 10);     

      //Calculate the numeric equivalent of file permission
      if (no == 4 && chkBox.checked) {
            number += r;
      } else if (no == 4 && (!chkBox.checked)) {
            number = number - r;
      }
      if (no == 2 && chkBox.checked) {
            number += w;
      } else  if (no == 2 && (!chkBox.checked)){
            number = number - w;
      }
      if (no == 1 && chkBox.checked) {
            number += x;
      } else if (no == 1 && (!chkBox.checked)) {
            number = number - x;
      }

      document.chmod[total].value = number; 

      //Display the numeric equivalent for each class in the order of owner, group, others
      document.getElementById("total_value").innerHTML = document.chmod["total_owner"].value + document.chmod["total_group"].value + document.chmod["total_other"].value;
}

Fig 1: Numeric value for desired file permission

Using the application:

  • Simply install and launch the application on your device.
  • Click on the checkboxes corresponding to the user and its permission, in order to set/unset the desired access permission.
  • chmod numeric value would be changed and displayed upon the checkbox set/unset.
  • The resultant numeric value can be used

 

Build Requirements:

The application is built for devices with Tizen 2.0 firmware.

SDK Environment used:  2.0.0a2

File attachments: