unix_perms

Crates.iounix_perms
lib.rsunix_perms
version0.1.4
created_at2025-05-25 16:46:05.236315+00
updated_at2025-05-28 19:08:17.739186+00
descriptionConverts Unix file mode metadata into symbolic rwx strings, emulating the output of the ls -l command. Ideal for Rust-based system tools or file inspection utilities.
homepagehttps://github.com/santoshxshrestha/unix_perms
repositoryhttps://github.com/santoshxshrestha/unix_perms
max_upload_size
id1688515
size6,648
Santosh Shrestha (santoshxshrestha)

documentation

https://github.com/santoshxshrestha/unix_perms#readme

README

unix_perms

A lightweight Rust library for displaying Unix-style file permissions like -rwxr-xr--, mimicking the output of ls -l.

๐Ÿงพ Features

  • Converts file mode bits (from std::fs::Metadata) into symbolic rwx string format
  • Supports regular files, directories, symlinks, and other file types
  • No unnecessary dependencies โ€” pure and minimal

๐Ÿ”ง Example

display_permissions

use unix_perms::display_permissions;
use std::fs::metadata;

fn main() -> std::io::Result<()> {
    let meta = metadata("some_file.txt")?;
    let mode_str = display_permissions(&meta);
    println!("{}", mode_str); // Output: -rw-r--r--
    Ok(())
}

get_owner_and_group

use std::fs;
use unix_perms::get_owner_and_group;

fn main() {
    let path = ".";

    if let Ok(entries) = fs::read_dir(path) {
        for entry in entries.flatten() {
            let file_name = entry.file_name().into_string().unwrap_or("???".to_string());
            let (owner, group) = get_owner_and_group(entry);
            println!("{:<20} owner: {:<10} group: {}", file_name, owner, group);
        }
    }
}

get_name

use unix_perms::get_name;
fn main() {
    let id = 0;
    let name = get_name(id);
    println!("{}", name); //Output: root
}

๐Ÿ“ฆ Installation

Add this to your Cargo.toml:

[dependencies]
unix_perms = "0.1.0"

or you can directly use cargo

cargo install unix_perms

๐Ÿ“„ License

License: MIT

Commit count: 17

cargo fmt