You are here: Articles > UNIX > UNIX

 See more articles about "UNIX "

UNIX: advanced octal file permissions with chmod

 

The chmod command in various UNIX flavors like Solaris, Linux, Mac OSX, and others, allows the access controls of a file or directory to be set. This recipe describes the more complex octal chmod syntax.

See the recipe Set UNIX file access permissions with chmod for the basics of file permissions and chmod. This recipe is for users familiar with these concepts.



The permissions for each user type can be represented by an octal value. Each type of permission carries with it a value:



4   r  read

2   w  write

1   x  execute/cd



Putting these together in combination yields an octal number from 0 to 7. For example, read (4) and execute (1) permissions together are represented by 5 (4+1). Here is a table representing all of the possible values:



7   rwx    read, write, execute

6   rw-    read, write

5   r-x    read, execute

4   r--    read

3   -wx    write, execute

2   -w-    write

1   --x    execute

0   ---    no permissions



This seems more complex than using the ug+rw notation covered in the recipe linked above. The character-based syntax is useful for simple changes in file permissions, but it provides only relative changes in state, such that the resulting state is dependent on the values before running chmod. In addition, common real-world requirements can make the character-based syntax very complex.



Using octal syntax for chmod allows setting the absolute permissions for owner, group, and other in one quick command. The syntax requires three octal digits, each representing the owner, group, and other permissions, respectively. For example, to set rwx (7) for owner, r-x (5) for group, and no permissions (0) for other, use the following chmod command:



chmod 750 file



The learning curve is a little steeper for the octal syntax, but the benefits are great, too.

 

Also see ...

Recursive grep
H3This tip is for grepping a pattern even in the sub directories of a particular directory in addition to the files in the current directory. Since grep R is not available on all flavors, this can be really helpful./H3PThe command is as follows : br / br /div class="code"find

Kill the undesired UNIX processes in one go
H3This recipe is useful when one wants to kill all the processes belonging to one user or having a particular regular expression in the process name. One can use different options of "ps" and "grep" to kill the undesired process(es)./H3PThe following is the general syntax of this recipe b

Send HTML formatted mail from Unix using Sendmail
H3I have used this quite a bit and it works great for me. We're on an HP box running Unix 11.11. You can embed javascripts, css, etc. Pretty cool stuff. /H3Pdiv class="code"&40; br /echo "From&58; you@your_company.com" br /echo "To&58; you@your_company.com" br

UNIX: Shortcut to create a backup copy of a file
H3Copy and rename a file in a shorter step than the normal cp file file.bak/H3PIf you have a file named foobar and you want to make a backup copy named foobar.bak you could do br / br /div class="code"cp foobar foobar.bakP br /but what if the file has a long name, and you have

Place and manage tasks or jobs in the background from the comand line
H3Managing tasks or jobs from the command line or terminal is easy in unix flavors once you know the simple commands./H3PUnix, like other modern operating systems, can easily run multiple tasks at once. If you running from the command line or terminal, it is not obvious how to do this or mana