That's a great question!
While chown user:group file changes both the user and group, you can definitely change only the group of a file without affecting its owner.
To change only the group of a file, you use the chown command with a special syntax or the chgrp command.
Method 1: Using chown (recommended for consistency)
You can use chown and specify only the group, like this:
sudo chown :new_group_name example.txt
Notice the colon before new_group_name. This tells chown to only modify the group ownership, leaving the current user owner unchanged.
For example, if you wanted to change the group of example.txt to users (assuming a users group exists on your system), you would run:
sudo chown :users example.txt
Method 2: Using chgrp (specific for group changes)
There's also a dedicated command for changing just the group: chgrp.
sudo chgrp new_group_name example.txt
Using our example:
sudo chgrp users example.txt
Both methods will achieve the same result: changing only the group ownership of example.txt to users, while the file's owner remains the same. Remember, you'll still need sudo for these operations as changing ownership requires elevated privileges.
Give it a try in your terminal if you like! Let me know if you have more questions.