Function std::os::unix::fs::chown

source · []
pub fn chown<P: AsRef<Path>>(
    dir: P,
    uid: Option<u32>,
    gid: Option<u32>
) -> Result<()>
🔬This is a nightly-only experimental API. (unix_chown #88989)
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

#![feature(unix_chown)]
use std::os::unix::fs;

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