Oct 152009
 

Terminal should be ANSI compliant and support colour escape sequences. Modern terminal should do the job.

The following is a list of escape sequences

The ^[ is produced by pressing Ctrl-V then ESC

I’m using vi as text editor and there’s no problem with ctrl-V ESC, i’m not test it on other text editor.

^[[0m    - Reset the terminal characteristics
^[[1m    - emphasis (bold)

^[[30m    - Foreground black
^[[31m    - Foreground red
^[[32m    - Foreground green
^[[33m    - Foreground yellow
^[[34m    - Foreground blue
^[[35m    - Foreground magenta
^[[36m    - Foreground cyan
^[[37m    - Foreground white

Continue reading »

Oct 082009
 

Suppose we have umask 0002 for our user default permission.

    $ umask
    0002

Create new directory

    $ mkdir tmpdir

tmpdir directory created with its default permission 775

    $ ls -l
    ..........
    ..........
    drwxrwxr-x  2 harry harry      4096 Oct  8 06:59 tmp
    ..........
    ..........

Create new file

    $ touch tmpfile

tmpfile file created with its default permission 664

    $ ls -l
    -rw-rw-r--  1 harry harry 0 Oct  8 07:06 tmpfile

Now, let’s see how the file permission settings are calculated using boolean expressions with default umask 0002.

For e.g. consider the case where we have default umask value of 0002 – 0000 0000 0000 0010
1’s complement of 0002 – 1111 1111 1111 1101

For directories perform logical AND operation with 0777 (0000 0111 0111 0111). So

    1111 1111 1111 1101 (1’s complement of 0002)
    0000 0111 0111 0111 (0777, base permission of directory)
    —————-------------- AND
    0000 0111 0111 0101 = 0775

For files, perfom logical AND operation with 0666 (0000 0110 0110 0110), so

    1111 1111 1111 1101 (1’s complement of 0002)
    0000 0110 0110 0110 (0666, base permission of file)
    —————-------------- AND
    0000 0110 0110 0100 = 0664

we can try different combination of umask value, so we can get a clear picture on how umask is applied to determine default permission on newly created files or directories.