Migrate to RunxBuild and earn up to $50 in hosting credit on your first deposit.

Calculate your savings
unxBuild

chown Command in Linux: Change Owner, Group, and Recursive

Sean

Platform Writer

Jul 05, 2026
4 min read

chown command in Linux: chown user:group file to change owner and group, chown user file for owner only, chown :group file for group only, chown -R for recursive. The team that uses chown to fix ownership for web servers, app files, or shared directories has the standard tool.

chown Command in Linux: Change Owner, Group, and Recursive

Table of contents

Change owner and group

chown alice:developers file.txt
chown alice: file.txt   # set owner, leave group
chown :developers file.txt   # set group only

The team that uses user:group has both set. The team that uses just user or just group has the right precision.

Recursive

chown -R alice:developers /var/www/myapp/

Changes owner of directory and all contents. The team that uses -R for app directories has correct ownership throughout.

By UID/GID

chown 1000:1000 file.txt

Use numeric IDs (UID, GID) for systems where the username doesn’t exist. The team that uses numeric IDs has portable scripts.

Common use cases

Web server files:

sudo chown -R www-data:www-data /var/www/html/

User-uploaded files:

sudo chown alice:alice ~/uploads/

Shared directory:

sudo chown :team-shared /srv/shared/
sudo chmod 2775 /srv/shared/   # setgid for new files to inherit group

The team that uses chown + chmod has correct ownership and permissions.

chown vs chgrp

  • chown: change user AND/OR group.
  • chgrp: change group only.

The team that uses chown for both is fine. The team that uses chgrp for group-only is also fine.

Preserve root when changing

By default, chown clears setuid/setgid bits. To preserve:

chown --preserve-root -R alice /data/

The team that uses --preserve-root has safety on / (no accidental root changes).

By default, chown follows symlinks. To change the symlink itself:

chown -h alice symlink

The team that uses -h for symlinks has correct behavior.

FAQ

What’s the difference between chown and chmod?

chown: change owner/group. chmod: change permissions (rwx). The team that needs both uses both.

Can I chown a file I don’t own?

No (unless root). Only root can change ownership of files they don’t own.

Why does chown take so long on large directories?

It’s reading and updating inode metadata for each file. The team that uses chown on huge directories waits.

How do I chown to a user that doesn’t exist?

Use the UID. chown 1000 file.txt. The team that uses UID for portability works across systems with different users.

Can I undo a chown?

Not easily. You’d need to know the original owner:group. The team that records ownership before chown has rollback.

If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.

Useful related references:

#linux#chown#permissions#command#dev-infra