# unix

abstract fun unix(unixNumericOrSymbolic: String)(source)

Sets Unix style permissions. Accept values in two styles of notation:

- NUMERIC notation: uses 3 octal (base-8) digits representing permissions for the 3 categories of users; for example "755"
- SYMBOLIC notation: uses 3 sets of 3 characters, each set representing the permissions for one of the user categories; for example "rwxr-xr-x"

The NUMERIC notation consist of 3 digits having values from 0 to 7. 1st digit represents the OWNER, 2nd represents the GROUP while the 3rd represents OTHER users.

Each of the digits is the sum of its component bits in the binary numeral system. Each of the 3 bits represents a permission. 1st bit is the READ bit, adds 4 to the digit (binary 100). 2nd bit is the WRITE bit, adds 2 to the digit (binary 010). 3rd bit is the EXECUTE bit, adds 1 to the digit (binary 001).

See the examples below.

NOTE: providing the 3 numeric digits can also be done in the octal literal form, so "0740" will be handled identically to "740".

The SYMBOLIC notation consists of 3 sets of 3 characters. The 1st set represents the OWNER, the 2nd set represents the GROUP, the 3rd set represents OTHER users.

Each of the tree characters represents the read, write and execute permissions:

- `r` if READING is permitted, `-` if it is not; must be 1st in the set
- `w` if WRITING is permitted, `-` if it is not; must be 2nd in the set
- `x` if EXECUTING is permitted, `-` if it is not; must be 3rd in the set

000 | --------- | no permissions
700 | rwx------ | read, write &execute only for owner
770 | rwxrwx--- | read, write &execute for owner and group
111 | --x--x--x | execute
222 | -w--w--w- | write
333 | -wx-wx-wx | write &execute
444 | r--r--r-- | read
555 | r-xr-xr-x | read &execute
666 | rw-rw-rw- | read &write
740 | rwxr----- | owner can read, write &execute; group can only read; others have no permissions

An example usage of this method would be configuring a copy task and explicitly specifying the destination file permissions:

    from(...)
    into(...)
    filePermissions { unix("r--r--r--") }

Content copied to clipboard

abstract fun unix(unixNumeric: Int)(source)

Sets Unix style numeric permissions. See unix for details.

As described there, the value is expected to come from the range of 3 digit octal numbers, i.e. from 0 (included) to 512 (excluded).

When represented in octal form, the numbers have the same meaning as their string counterparts (see unix), so the following statements are all equivalent:

      unix("0740")         // octal number as string
      unix("740")          // octal number as string (no prefix)
      unix(0740)           // octal int literal
      unix(482)            // decimal int literal
      unix("rwxr-----")    // non-numeric string

Content copied to clipboard