Share
Explore BrainMass

how to convert a octal value for UNIX file permissions to a text value

Can anyone explain to me how to convert a octal value for UNIX file permissions to a text value to display on screen. For example I need to write code in C++ that would take in octal value 100666 and display rw-rw-rw

I have found this information but still can not figure out the conversion.

Octal digit Text equivalent Binary value Meaning
0 --- 000 All types of access are denied
1 --x 001 Execute access is allowed only
2 -w- 010 Write access is allowed only
3 -wx 011 Write and execute access are allowed
4 r-- 100 Read access is allowed only
5 r-x 101 Read and execute access are allowed
6 rw- 110 Read and write access are allowed
7 rwx 111 Everything is allowed

Solution Preview

The chart you have given only shows how the octal system is interpreted in binary. This is not the octal system that is practically used in unix.
For this you need to know about Octal permissions in Unix as follows:

Octal Permissions

Unix systems use octal (base-8) numbers to specify the various permission bits. These correspond to human-readable permissions as follows:
Octal Number Human-Readable Letter
4 read r
2 write w
1 execute x
0 none

These permissions are additive?that is, by adding up the numbers corresponding to the permissions that you want to grant, ...

Solution Summary

This job explores how to convert a octal value for UNIX file permissions to a text value.

$2.19