Skip to main content

chown Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for changing file and directory ownership with chown in Linux

chown changes file and directory ownership in Linux. This cheatsheet covers user and group changes, recursive ownership updates, common patterns, and safe usage.

Basic Syntax

Use these core command forms for chown.

CommandDescription
chown USER FILEChange file owner
chown USER:GROUP FILEChange owner and group
chown :GROUP FILEChange group only
chown USER: FILEChange owner and set group to user’s login group
chown --reference=REF FILECopy owner and group from another file

Common Examples

Common ownership changes for files and directories.

CommandDescription
chown root file.txtSet owner to root
chown www-data:www-data /var/www/index.htmlSet owner and group for a web file
sudo chown $USER:$USER file.txtReturn ownership to current user
chown :developers app.logChange group only
chown --reference=source.txt target.txtMatch ownership of another file

Recursive Changes

Apply ownership updates to full directory trees.

CommandDescription
chown -R USER:GROUP /pathRecursively change owner and group
chown -R USER /pathRecursively change owner only
chown -R :GROUP /pathRecursively change group only
chown -R -h USER:GROUP /pathChange symlink ownership itself during recursion
chown -R --from=OLDUSER:OLDGROUP NEWUSER:NEWGROUP /pathChange only matching current ownership

Control how chown treats symbolic links.

CommandDescription
chown USER:GROUP symlinkChange target by default
chown -h USER:GROUP symlinkChange symlink itself (not target)
chown -R -H USER:GROUP /pathFollow symlink command-line args to directories
chown -R -L USER:GROUP /pathFollow all directory symlinks
chown -R -P USER:GROUP /pathNever follow symlinks (default)

Safe Patterns

Use these patterns to avoid ownership mistakes.

CommandDescription
chown --from=root root:root /path/fileChange 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/fileVerify ownership before and after changes
id usernameConfirm user and group names exist

Common Errors

Quick checks when ownership changes fail.

IssueCheck
Operation not permittedYou need root privileges; run with sudo
invalid userVerify user exists with getent passwd username
invalid groupVerify group exists with getent group groupname
Changes did not apply recursivelyConfirm -R was used
Access still denied after chownCheck permission bits with ls -l and ACLs

Use these guides for full ownership and permissions workflows.

GuideDescription
Chown Command in LinuxFull chown guide with examples
chgrp Command in LinuxChange file group ownership
How to Change File Permissions in Linux (chmod command)Update permission bits
Understanding Linux File PermissionsOwnership and permission model
How to List Groups in LinuxCheck group membership and IDs