While working with Linux file permissions, I discovered an interesting variation in chown syntax that isn't well documented. The traditional format we all know is:
chown user:group filename
But during some system administration work, I accidentally used:
chown user.group filename
To my surprise, it worked perfectly! This led me down a rabbit hole of investigation.
After digging through old Unix documentation and POSIX standards, I found that the dot notation actually predates the colon syntax. Early Unix systems (pre-System V) used the dot as the separator. The colon became standardized later for better shell compatibility, as dots could conflict with filenames in some contexts.
Modern implementations (including GNU coreutils) maintain backward compatibility by supporting both formats. Here's a quick test you can run:
# Create test file
touch testfile.txt
# Both commands produce identical results
sudo chown root.root testfile.txt
sudo chown root:root testfile.txt
# Verify with ls -l
ls -l testfile.txt
While both work, there are some practical considerations:
- Colon syntax is the POSIX standard and recommended for scripts
- Dot syntax might be preferred in certain scenarios:
- When working with Windows-interoperability tools that misinterpret colons
- In some restricted shells where colon has special meaning
- For legacy system support
Both formats work with all chown variants. Here are some practical examples:
# Recursive ownership change
chown -R www-data.www-data /var/www/
# Reference file syntax
chown --reference=source.txt target.txt
# Changing just the group (both formats)
chown :developers project/
chown .developers project/
# Combined with chmod
chown deploy.deploy /app && chmod 750 /app
Be aware of these edge cases:
# Problem: Dot in username
useradd john.doe
chown john.doe:group file.txt # Wrong - interprets as user=john, group=doe:group
chown 'john.doe':group file.txt # Correct
# Solution alternatives:
chown john.doe.group file.txt
chown 'john.doe:group' file.txt
The dot syntax can be particularly problematic when dealing with usernames or groups that contain dots. Always test with ls -l after making changes.
Looking at the GNU coreutils source code, the parsing happens in lib/userspec.c, where both separators are explicitly handled:
/* Simplified representation of the actual code */
if (strchr (spec, ':') || strchr (spec, '.')) {
parse_user_group(spec);
}
This explains why both formats work - it's not shell interpretation but built into chown itself.
In Linux system administration, both these commands achieve the same result of changing file ownership:
chown user:group file
chown user.group file
The dot notation (user.group) actually predates the colon format. This originates from early Unix systems where the dot was the standard separator. Modern Linux systems maintain backward compatibility, though most documentation now primarily shows the colon format.
Both GNU coreutils and BSD implementations support both formats. The behavior is handled at the libc level rather than being a shell interpretation. Here's how it works internally:
if (separator != ':' && separator != '.')
error("invalid user-group separator");
These examples demonstrate equivalent functionality:
# Changing ownership of a directory recursively
chown -R www-data.apache /var/www
chown -R www-data:apache /var/www
# Changing ownership of multiple files
chown deploy.deployers *.php
chown deploy:deployers *.php
While both formats work, the colon syntax (user:group) is now considered the standard because:
- It's more explicitly documented in most modern systems
- Reduces potential confusion with dotted usernames
- Aligns with similar syntax in other commands (like useradd)
In some shells (particularly older versions), the dot might be interpreted as a command separator. Using quotes can prevent any potential issues:
chown "user.group" file
chown 'user.group' file