Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use the chown Command on Ubuntu 16.04 / 18.04 with Examples

#1
How to use the chown Command on Ubuntu 16.04 / 18.04 with Examples


For new users and students looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS…. It’s a great platform for beginners to start learning Linux on… Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices…


The same way you use your mouse and keyboard to change files and folder permissions or perform others simple tasks on Microsoft Windows OS, Ubuntu also makes it that easy for you… Just like how simple it is to work on Windows computers, Ubuntu desktop is easy as well and great for beginners.

However, when you’re learning to use and understand Ubuntu Linux, you’ll also want to learn the commands behind the graphics and mouse-clicking… and how to use them…  This tutorial is going to show you how.



This post shows new users and students what the chown command is and how to use it.


When you’re ready to learn how to use the chown commands, follow the guide below:



About chown command:



The chown command is used by system adminstrators to change the ownership of files and directories on Linux filesystems…. It allows superuser 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 tree major groups to apply permissions to… these are:



User  — These permissions apply to a single user who has special access to the file. This user is called the owner.
Group  — These apply to a single group of users who have 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 automatically is assigned owership of the file… 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 systax’s options can be reordered.. but straight format must be followed.,.
Below is an example syntax of how to use the chown comamnd….

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

Options:

The command line options are switches or flags that determined how the commands are executed or controlled… they modify the behavior of the command… they are separated by spaces and followed after the commands options…
Below are some options of the chown command:

    FILE…

Replace FILE… with the file you want to change it ownership.. If the file doesn’t already exist, the command will fail and not execute…….

-c, –changes

Use the -c or –changes option to report only when a change is made

-f, –silent, –quiet

Use the -f or –silent, –quiet to suppress most error messages

-R, –recursive

Use the -R or –recursive option to operate on files and directories recursively

-v, –verbose

Use the -v or –verbose option to output a diagnostic for every file processed

-h, –help

display this help message and exit


Examples:

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

If you want to give John owership of a file named Confidential, you run the commands below…


Code:
chown john Confidential


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


Code:
chown john:private Confidential


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


Code:
sudo chown john:private Confidential


The commands above give John ownership but assign the private group as group owner of the Confidential file… If access is granted to the private group, all members of that group will be able to access the Confidential file…

To change the ownership and group of an entire directory, including sub-directories, you add the -R option…


Code:
sudo chown -R john:private directories


In the example above, the chown command will give John user ownership but make the private group the group 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

     --dereference      affect the referent of each symbolic link (this is
                        the default), rather than the symbolic link itself


 -h, --no-dereference   affect symbolic links instead of any referenced file
                        (useful only on systems that can change the
                        ownership of a symlink)
     --from=CURRENT_OWNER:CURRENT_GROUP
                        change the owner and/or group of each file only if
                        its current owner and/or group match those specified
                        here.  Either may be omitted, in which case a match
                        is not required for the omitted attribute
     --no-preserve-root  do not treat '/' specially (the default)
     --preserve-root    fail to operate recursively on '/'
     --reference=RFILE  use RFILE's owner and group rather than
                        specifying OWNER:GROUP values


 -R, --recursive        operate on files and directories recursively


The following options modify how a hierarchy is traversed when the -R
option is also specified.  If more than one is specified, only the final
one takes effect.


 -H                     if a command line argument is a symbolic link
                        to a directory, traverse it

 -L                     traverse every symbolic link to a directory
                        encountered

 -P                     do not traverse any symbolic links (default)

     --help     display this help and exit

     --version  output version information an



If you edit something as root you may want to chown the permissions back to the user like so.


Code:
chown -R steam:steam /home/steam
[Image: 8OHl5AB.png]
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016