diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index ac71abd3804..4e4a7c052dc 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -194,6 +194,7 @@ fn parse_gid(group: &str, spec: &str) -> UResult> { /// * `"owner:group"`, /// * `"owner"`, /// * `":group"`, +/// * `"owner:"`, /// /// and the owner or group can be specified either as an ID or a /// name. The `sep` argument specifies which character to use as a @@ -230,7 +231,13 @@ fn parse_spec(spec: &str, sep: char) -> UResult<(Option, Option)> { )); } - Ok((uid, gid)) + if gid.is_none() && !user.is_empty() && spec.ends_with(':') { + // we have input of the form user: and should change the group to the users login group as + // per GNU + Ok((uid, Some(entries::usr2gid(user)?))) + } else { + Ok((uid, gid)) + } } #[cfg(test)]