How to use the chown command on Ubuntu Linux with examples

|

|

The chown command is a system tool used by administrators to change file and directory ownership on Linux systems, mainly used within Ubuntu, an open-source Linux operating system ideal for beginners. With this command, superusers can regulate access to specific files or directories, mimicking the function of using a mouse and keyboard on a GUI.…

The chown command is used by system administrators to change the ownership of files and directories on Linux filesystems.

It is mainly used by system administrators to give specific users or groups access to files and directories.

Using the chown command, you can change the user and group ownership of files and directories. This is particularly useful when different users or groups need to access specific files or directories.

Additionally, the chown command can restrict access to files and directories, which is important for maintaining security on your Ubuntu Linux system.

Ubuntu is an open-source Linux operating system that runs on desktops, laptops, servers, and other devices.

About chown command:

The chown command is used by system administrators to change the ownership of files and directories on Linux filesystems. In addition, it allows superusers to change and restrict access to files and directories on Linux systems.

Like using your mouse and keyboard to add and remove users’ access from files and folders in the GUI. The chown is the way to do it on the command line.

Linux has three major groups to which you can apply for permissions.


User –– These permissions apply to a single user with special access to the file. This user is called the owner.
The group — These apply to a single group of users with access to the file. This group is the owning group.
Other These apply to every other user on the system. These users are known as others or the world.


When a file is created, the user is automatically assigned ownership. And the group becomes the user’s default group.

Syntax:

The syntax is the rule and format of how the chown command can be used. The syntax options can be reordered. But a straight format must be followed.,.

Below is an example syntax of how to use the chown command.

chown [OPTION]. [OWNER][:[GROUP]] FILE.

Options:

The command line options are switches or flags that determine how the commands are executed or controlled. They modify the behavior of the command. They are separated by spaces and followed after the command’s options.

Below are some options for the chown command:

    FILE.Replace FILE. With the file, you want to change its ownership. If the file doesn’t exist, the command will fail and not execute.
-c, –changesUse the -c or –changes option to report only when a change is made
-f, –silent, –quietUse them -for –silent, –quiet to suppress most error messages
-R, –recursiveUse the -R or –recursive option to operate on files and directories recursively
-v, –verboseUse the -v or –verbose option to output a diagnostic for every file processed
-h, –helpdisplay this help message and exit

Examples:

Below are some examples of how to run and use the chown on Ubuntu Linux.

You run the commands below if you want to give John ownership of a Confidential file.

chown john Confidential

If you wish to make John the owner but make the private group owner, you run the commands below.

chown john:private Confidential

If you’re not logged in as a root account, you may have to use the sudo command.

sudo chown john:private Confidential

The commands above give John ownership but assign the private group as the group owner of the Confidential file. All members can access the Confidential file if access is granted to the private group.

You add the – R option to change the ownership and group of an entire directory, including sub-directories.

sudo chown -R john:private directories

In the example above, the chown command will give John user ownership but make the private group the owner of directories.

When you run chown with the –help option, you’ll see the help text below:

Usage: chown [OPTION]. [OWNER][:[GROUP]] FILE.
  or:  chown [OPTION]. --reference=RFILE FILE.
Change the owner and/or group of each FILE to OWNER and/or GROUP.
With --reference, change the owner and group of each FILE to those of RFILE.

  -c, --changes          like verbose but report only when a change is made
  -f, --silent, --quiet  suppress most error messages
  -v, --verbose          output a diagnostic for every file processed

      --help     display this help and exit
      --version  output version information an

That’s it!

I hope you like it, and please come back soon for more Ubuntu Linux commands!

Like this:



One response to “How to use the chown command on Ubuntu Linux with examples”

  1. brisante Avatar
    brisante

    Thanks for the info, very well written

Leave a Reply to brisante Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.