| .gitignore | ||
| LICENSE | ||
| perms.nim | ||
| README.md | ||
permfix
A fast, safe, and declarative CLI utility written in Nim for recursively setting file and directory permissions.
A Robust File Permission Utility
permfix is a small, fast, and reliable command-line utility written in Nim to recursively set file and directory ownership and permissions. It is designed as a safe and powerful replacement for complex or brittle shell scripts.
Why permfix?
While chown and chmod shell commands are powerful, creating a script to handle logic for different permission schemes can become cumbersome and error-prone. permfix provides a compiled, type-safe, and explicit alternative that ensures you apply the correct permissions every time, with clear, user-friendly commands.
It's built to be:
- Safe: The tool validates user and group inputs and uses Nim's type system to prevent common errors.
- Explicit: No hidden magic. The commands clearly state their intent.
- Fast: Compiled to a native binary, it operates with maximum efficiency.
- Portable: The final compiled binary has zero dependencies and can be placed anywhere on a Linux/macOS system.
Features
- Recursively walks directory structures.
- Sets ownership (user and group).
- Applies one of two permission modes:
secure: A restrictive mode ideal for private media libraries (750for dirs,640for files).permissive: A more open mode for collaborative group access (775for dirs,664for files).
- Validates that specified user and group exist before making changes.
- Provides clear, verbose output of actions performed.
Installation
1. Dependencies
permfix requires the cligen library. You can install it using Nim's package manager, nimble:
nimble install cligen
2. Compilation
To build the permfix binary from the perms.nim source file, run the following command. This creates a small, optimized, and static executable.
nim c -d:release --out:permfix perms.nim
3. (Optional) Move to PATH
For system-wide access, move the compiled binary to a directory in your $PATH:
sudo mv permfix /usr/local/bin/
Usage
⚠️ Important: You must run permfix with sudo or as the root user, as changing file ownership is a privileged operation.
The tool requires a mode (secure or permissive), an owner, a group, and the target path.
Secure Mode
Applies rwxr-x--- (750) to directories and rw-r----- (640) to files. The owner has full control, the group has read-only access, and others have no access.
sudo permfix secure --owner=markus --group=media /path/to/your/movies
Permissive Mode
Applies rwxrwxr-x (775) to directories and rw-rw-r-- (664) to files. Useful when other users or services in the same group need write access.
sudo permfix permissive --owner=markus --group=downloads /path/to/your/games
License
This project is licensed under the EUPL-1.2 License.