The chown command in Unix-like operating systems is used to change the owner and group of files and directories. This cheat sheet covers essential chown commands for managing ownership and group assignments.
Introduction:
The chown command is a fundamental tool for changing the owner and group of files and directories on Unix-based systems. It allows users to transfer ownership and assign group membership.
Basic Commands:
Command
Description
chown [owner]:[group] [file/directory]
Change both owner and group.
chown :[group] [file/directory]
Change only the group.
chown [owner] [file/directory]
Change only the owner.
Recursive Changes:
Command
Description
chown -R [owner]:[group] [directory]
Recursively change owner and group for a directory and its contents.
chown -R [owner] [directory]
Recursively change only the owner for a directory and its contents.
chown -R :[group] [directory]
Recursively change only the group for a directory and its contents.
Numerical User and Group IDs:
Command
Description
chown [owner_id].[group_id] [file/directory]
Change owner and group using numerical IDs.
chown [owner_id] [file/directory]
Change only the owner using a numerical ID.
chown .[group_id] [file/directory]
Change only the group using a numerical ID.
Examples:
Command
Description
chown user:group file.txt
Change owner to user and group to group for file.txt.
chown -R root:admin /etc/config
Recursively change owner to root and group to admin for /etc/config and its contents.
chown 1000:1000 /home/user/documents
Change owner and group to user with UID/GID 1000 for /home/user/documents.
The chown command is essential for managing file and directory ownership on Unix-like systems. This cheat sheet provides essential commands for changing owners and groups, performing recursive changes, using numerical IDs, and more. Whether you are a regular user or a system administrator, understanding these chown commands will help you manage file ownership efficiently.