Linux

chown command Linux to Change owner with examples

chown Command linux is an administrator command is used to change the owner user and/or group of each given file or directory.

chown Command syntax

    
     chown [options] newowner directoryname/filename

    
   

chown options

  • -c, –changes : like verbose but report only when a change is made.
  • –reference=RFILE :use RFILE’s owner and group rather than specifying OWNER:GROUP values
  • -f, –silent, –quiet:suppress most error messages.
  • –dereference : affect the referenced file of each symbolic link rather than the symbolic link itself. This is the default.
  • -v, –verbose :output a diagnostic for every file processed.
  • –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.
  • -h, –no-dereference:affect symbolic links instead of any referenced file. This is useful only on systems that can change the ownership of a symlink.
  • –preserve-root:Do not operate recursively on ‘/’.
  • –no-preserve-root:do not treat ‘/’ (the root directory) in any special way. This is the default.
  • -R, –recursive:operate on files and directories recursively.
  • -L :traverse every symbolic link to a directory encountered.
  • -H :if a command line argument is a symbolic link to a directory, traverse it.
  • -P :do not traverse any symbolic links. This is the default.
  • –help :display this help and exit.
  • –version :output version information and exit.

chown Command Examples

Changing owner for directories recursively

The ownership of the directories and files contained in them can be changed recursively with -R option.
    
     chown -R exaccount /home/example/
    
   

chown Verbose output

The –verbose option shows all the ownership changing. It outputs the diagnostics for each file processed

    
     chown -R –verbose david /home/david/
#changed ownership of ‘/home/david/emails’ to david
#changed ownership of ‘/home/david/blogs’ to david
#changed ownership of ‘/home/david/plugins’ to david
    
   

Preserve root

To prevent changing the ownership of / directory recursively, –preserve-root is used.
    
     chown -R –preserve-root david /
#chown: changing ownership of ‘/proc/1/tasks/1/fd’: Permission denied
#chown: changing ownership of ‘/proc/1/tasks/1/fd/status’: Permission denied

    
   

chown Silent operation

Let’s consider the following scenario .As normal users cannot change the ownership of files owned by others. Then an error is displayed when a that user tries to change the ownership.

    
     chown david /etc/

    
   
chown: changing ownership of `/etc/’: Operation not permitted But if by passing -f or –silent or –quiet option, the error is not displayed.
    
     chown -f david /etc/
    
   
XsoftHost Support

Share

Recent Posts

Add Extra IP addresses to server configuration On Ubuntu 17.10 and later

Each failover IP address will need its own line in the configuration file. The configuration…

4 years ago

Create RAID Arrays with mdadm on Ubuntu

What is mdadm? The mdadm utility can be used to create and manage storage arrays…

4 years ago

How to change the maximum upload file size for PHP

There are several scenarios that you might need to increase or decrease your php maximum…

6 years ago

How to install Let’s Encrypt Plugin in WHM/cPanel

What is Let’s Encrypt? Let’s Encrypt is a free certificate authority provided by the Internet…

6 years ago

How to install python in my cPanel and add py extension

Python normally installed on all cPanel hosting server because most of Centos/red hat update system…

6 years ago

How to install and enable GUI GNOME Desktop on centos 7

Usually CentOS 7 comes in a numbers of variants, For most users, there are two…

6 years ago