What is Linux chown Command
chown is an administrator command is used to change the owner user and/or group of each given file or directory.
chown Command syntax
chown Command 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 Verbose output
The –verbose option shows all the ownership changing. It outputs the diagnostics for each file processed
chown Preserve root
To prevent changing the ownership of / directory recursively, –preserve-root is used.
chown Silent operation
Lets 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.
But if by passing -f or –silent or –quiet option, the error is not displayed.
2,497 total views, 1 views today