June 29, 2007

Setting the permission mode using the chmod utility in octal mode (Unix)?

If I didn't want to share the "a file" with anyone and I also want to prevent overwriting/modifying the file by my own mistakes (read-only). How should I change the file permission mode using the chmod utility in octal mode?

  1. (Red Hat Linux)
  2. chmod 400 filename

    would give permissions -r——–, so read-only for owner, no access for group and others.

    Basically, there are three sets of bits, one each for user, group and other (in that order). Each set has three bits and each bit is an on/off switch for read, write and execute (in that order too.)

    Since octal numbers can be represented by three bits, that makes them ideal for unix permission flags. There is one octal digit per set.

    1 = 001 = –x
    2 = 010 = -w-
    4 = 100 = r–

    To get the permissions you want, just add up the octal numbers of the bits you want to activate.

    001+100 = 101 (1 + 4 = 5) r-x (read-only, executable)
    010+100 = 110 (2 + 4 = 6) rw- (read/writable, non-executable)
    001+010+100 = 111 (1 + 2 + 4 = 7) rwx

    A long explanation for a simple question. Hope that helps.

Tags: ,

Tell a Friend Today!

del.icio.us Digg Furl Reddit Ask BlinkList blogmarks Blogg-Buzz Google Ma.gnolia Netscape ppnow Rojo Shadows Simpy Socializer Spurl StumbleUpon Tailrank Technorati Windows Live Wists Yahoo! Help

Permalink • Print

Track this entry

RSS BlogPulse

RSS Technorati Cosmos

Related Searches

, , , ,