Allgemein

chown Cheatsheet

chown Cheatsheet

Basic Syntax

Use these core command forms for chown.

Command Description
chown USER FILE Change file owner
chown USER:GROUP FILE Change owner and group
chown :GROUP FILE Change group only
chown USER: FILE Change owner and set group to user’s login group
chown --reference=REF FILE Copy owner and group from another file

Common Examples

Common ownership changes for files and directories.

Command Description
chown root file.txt Set owner to root
chown www-data:www-data /var/www/index.html Set owner and group for a web file
sudo chown $USER:$USER file.txt Return ownership to current user
chown :developers app.log Change group only
chown --reference=source.txt target.txt Match ownership of another file

Recursive Changes

Apply ownership updates to full directory trees.

Command Description
chown -R USER:GROUP /path Recursively change owner and group
chown -R USER /path Recursively change owner only
chown -R :GROUP /path Recursively change group only
chown -R -h USER:GROUP /path Change symlink ownership itself during recursion
chown -R --from=OLDUSER:OLDGROUP NEWUSER:NEWGROUP /path Change only matching current ownership

Symlinks and Traversal

Control how chown treats symbolic links.

Command Description
chown USER:GROUP symlink Change target by default
chown -h USER:GROUP symlink Change symlink itself (not target)
chown -R -H USER:GROUP /path Follow symlink command-line args to directories
chown -R -L USER:GROUP /path Follow all directory symlinks
chown -R -P USER:GROUP /path Never follow symlinks (default)

Safe Patterns

Use these patterns to avoid ownership mistakes.

Command Description
chown --from=root root:root /path/file Change only if current owner matches
find /path -user olduser -exec chown newuser {} + Target only files owned by one user
find /path -group oldgroup -exec chown :newgroup {} + Target only one group
ls -l /path/file Verify ownership before and after changes
id username Confirm user and group names exist

Common Errors

Quick checks when ownership changes fail.

Issue Check
Operation not permitted You need root privileges; run with sudo
invalid user Verify user exists with getent passwd username
invalid group Verify group exists with getent group groupname
Changes did not apply recursively Confirm -R was used
Access still denied after chown Check permission bits with ls -l and ACLs

Related Guides

Use these guides for full ownership and permissions workflows.

Guide Description
Chown Command in Linux Full chown guide with examples
chgrp Command in Linux Change file group ownership
How to Change File Permissions in Linux (chmod command) Update permission bits
Understanding Linux File Permissions Ownership and permission model
How to List Groups in Linux Check group membership and IDs