chown command in Linux is a powerful utility for changing the owner or the
group associated with a file or a directory. This article will delve into
chown command, its syntax, various options, and examples to provide a
The basic syntax of the
chown command is as follows:
chown [OPTIONS] [OWNER][:[GROUP]] FILE...
OWNER: The username or the numeric user ID of the new owner.
GROUP: The name or numeric ID of the new group.
FILE: The name of the file or directory whose owner/group you want to change.
|Operate on files and directories recursively.
|Affect the referent of each symbolic link.
|Affect symbolic links instead of any referenced file.
|Change the owner and/or group of each file only if its current owner and/or group match those specified.
|Suppress most error messages.
|Output a diagnostic for every file processed.
Creating Example Users and Files
Before diving into examples, let's create a couple of users and a sample text file. You can run these commands to set up your environment:
# Create new users
sudo useradd alice
sudo useradd bob
# Create a sample text file
echo "This is a sample file." > sample.txt
Change the Owner of a File
sudo chown alice sample.txt
This command changes the ownership of
sample.txtto the user
Change the Group of a File
sudo chown :alice sample.txt
This command changes the group of
Change Both the Owner and the Group
sudo chown alice:alice sample.txt
This changes both the owner and the group of
Use with Options
sudo chown -R alice:alice /path/to/directory
This command will recursively change the owner and group for
/path/to/directoryand all files within it to
sudo chown --from=bob alice sample.txt
This changes the owner from
aliceonly if the current owner is
sudo chown -v alice:alice sample.txt
This will provide a verbose output for the operation.
chown command is an essential utility for managing file and directory
ownership in a Linux system. With its various options and the ability to handle
multiple files and directories at once,
chown is versatile and crucial for
Linux system administration.
What Can You Do Next 🙏😊
If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for software developers.