std::os::unix::fs

Function chown

1.73.0 · source
pub fn chown<P: AsRef<Path>>(
    dir: P,
    uid: Option<u32>,
    gid: Option<u32>,
) -> Result<()>
Available on Unix only.
Expand description

Change the owner and group of the specified path.

Specifying either the uid or gid as None will leave it unchanged.

Changing the owner typically requires privileges, such as root or a specific capability. Changing the group typically requires either being the owner and a member of the group, or having privileges.

If called on a symbolic link, this will change the owner and group of the link target. To change the owner and group of the link itself, see lchown.

§Examples

use std::os::unix::fs;

fn main() -> std::io::Result<()> {
    fs::chown("/sandbox", Some(0), Some(0))?;
    Ok(())
}