DEV Community

ehmicky
ehmicky

Posted on

Swiss Army knife for Unix permissions

Unix file permissions can take many shapes: symbolic (ug+rw), octal (660) or a list of characters (drw-rw----).

unix-permissions (https://github.com/ehmicky/unix-permissions) enables using any of these (instead of being limited to a single one) with any Node.js or CLI command.

This library can also perform operations on Unix permissions such as:

  • testing, setting and unsetting. Using bitwise operations (|, &, ^, ~) can be tedious and error-prone otherwise.
  • validating syntax.
  • normalizing. For example u+r,u+w can be shortened to u+rw.
  • inverting. For example a umask of 117 means new files will be created with 661 permissions.
  • checking the minimal or maximal permissions among a list of them. This can be useful to aggregate all the permissions of several files, e.g. during a directory recursion.

Feel free to provide me with feedback on dev.to or on GitHub!

Top comments (0)