file-ownership
Introduction
Linux files and directories always belong to a user and group. That is what we call ownership. If this can be boring to new users, remember that this is a huge part of what makes Linux as secure as it is.
Check current ownership
Check ownership in the current directory:
ls -l
Example output:
Syntax of the output is:
d
for directory or-
for fileuser, then group, then others permissions
number specifies the number of links or directories inside of a directory
The user that owns the file, or directory
The group that file or directory belongs to
The size in bytes
The date of last modification
The name of the file
Check ownership from all files and hidden files of any directory
ls -al /path/to/file/or/dir
Sample output:
All these commands require elevated privileges!
Change owner
Change owner from files or directories
Command
chown
As usual, chown --help
will provide you with all available arguments
Single file syntax
chown newowner /path/to/file/or/directory
Recursive syntax (include sub files and directories)
chown -R newowner /path/to/directory
Example
chown -R myuser /home/myuser
Group ownership
Change group ownership on files or directories
Command
chgrp
As usual, chgrp --help
will provide you with all available arguments
Single file syntax
chgrp newgroup /path/to/dir/or/file
Recursive syntax (include sub files and directories)
chgrp -R newgroup /path/to/dir/
User and group ownership
Change user and/or ownership for files and directories at the same time
Command
chown
As usual, chown --help
will provide you with all available arguments
Single file command
chown user:group /path/to/dir/or/file
Recursive
chown -R user:group /path/to/dir
Example:
chown -R myuser:myuser /home/myuser
Last updated