I have to change a file/directory's ownership using chmod
. I know only the owner's username but want to change the default group name simultaneously. At this stage the group name is not decided so I am putting same as the username:
chown -R username:username path_to_dir
Command may run for various systems/users. So my concern is, will Linux always have a pair username(user):username(group) OR at some point this default group_name may give error.
Although I have started to find GID from the user belongs
id username | tr '(=)' ':' | awk -F: '{print $3}
But for knowledge I want to know. Till now analysis of /etc/passwd
/etc/groups
except few users like "shutdown,halt,sync,operator" all users have listed in groups as well.
EDIT 1: id -gn username is also good option
id -g username
?id -gn username
which prints the name instead of the ID.