How do I use chmod and chown command under Linux / Unix operating systems?
Use the chown command to change file owner and group information. Use the chmod command to change file access permissions such as read, write, and access.
Use the chown command to change file owner and group information. Use the chmod command to change file access permissions such as read, write, and access.
chown command
chown command changes the user and/or group ownership of for given file. The syntax is:
chown owner-user file chown owner-user:owner-group file chown owner-user:owner-group directory chown options owner-user:owner-group file
Examples
First, list permissions for demo.txt, enter:
Sample outputs:
# ls -l demo.txt
Sample outputs:
-rw-r--r-- 1 root root 0 Aug 31 05:48 demo.txt
In this example change file ownership to vivek user and list the permissions, run:
Sample outputs:
# chown vivek demo.txt
# ls -l demo.txt
Sample outputs:
-rw-r--r-- 1 vivek root 0 Aug 31 05:48 demo.txt
In this next example, the owner is set to vivek followed by a colon and a group onwership is also set to vivek group, run:
Sample outputs:
# chown vivek:vivek demo.txt
# ls -l demo.txt
Sample outputs:
-rw-r--r-- 1 vivek vivek 0 Aug 31 05:48 demo.txt
In this example, change only the group of file. To do so, the colon and following GROUP-name ftp are given, but the owner is omitted, only the group of the files is changed:
Sample outputs:
# chown :ftp demo.txt
# ls -l demo.txt
Sample outputs:
-rw-r--r-- 1 vivek ftp 0 Aug 31 05:48 demo.txt
Please note that if only a colon is given, or if NEW-OWNER is empty, neither the owner nor the group is changed:
In this example, change the owner of /foo to "root", execute:
Likewise, but also change its group to "httpd", enter:
Change the owner of /foo and subfiles to "root", run:
Where,
# chown : demo.txt
In this example, change the owner of /foo to "root", execute:
# chown root /foo
Likewise, but also change its group to "httpd", enter:
# chown root:httpd /foo
Change the owner of /foo and subfiles to "root", run:
# chown -R root /u
Where,
- -R - Recursively change ownership of directories and their contents.
chmod command
The information about the chmod command is covered in our previous tutorial - "how to use change user rights using chomod command".
No comments:
Post a Comment