Modify the Linux file system directory, owner, and user groups
Linux each user must belong to a group, outside the group do not operate independently. In linux each file has, where the group concept of an owner other groups
- owner
- where the group
- Other groups
- change the user's group
owner
General file creator, who created the file, it is natural to become the owner of the file
You can see the owner of the file with the command ls -ahl
You can also use chown username file name to modify the file's owner
File's group
When a user creates a file, the file's group is the group to which the user belongs
You can see all the groups file with the command ls -ahl
You can also use chgrp group file name to modify the file resides group
Other groups
Other groups in addition to the owner and the user's group of open files, other users of the system are file
file permission
Ls -l content displayed as follows:
1
|
-rwxrw-r‐-1 root root 1213 Feb 2 09:39 abc
|
- The first character represents the file (-), directory (d), a link (l) - 10 different characters to determine what files users
- each of the remaining groups of three characters (rwx), read (r), write (w), execute (x)
- The first group rwx: file owner permissions are read, write and execute
- The second group rw-: user permissions and file owner is the same set of read and write but can not be executed
- The third group r--: not with the rights of other users of the same group is the owner of the file read and write can not be executed
Can also be expressed as numbers: r = 4, w = 2, x = 1 Thus rwx = 4 + 2 + 1 = 7
- The number of files indicates that the connection of 1
- root represents the user
- root represents the user's group
--1 213 indicates the file size (bytes)
- Feb 2 09:39 indicates the last modification date
- abc indicates the file name
Command to change the permissions
Chmod change the permissions of a file or directory
chmod 755 abc: abc given permission rwxr-xr-x
chmod u = rwx, g = rx, o = rx abc: u = supra user permissions, g = group permissions, o = different sets of permissions to other users
chmod ux, g + w abc: abc removing privileges to execute the user, increasing the write permission group
chmod a + r abc: Add read access to all users
View users and groups
1. First of all operations for prior experience, we look at the user and group under the current system. whoami view the current logged in user
[hadoop@mxhost1 ~]$ whoami
root
[hadoop@mxhost1 ~]$
2 .Passwd file system stores all current users, and group file / etc / group record.
3. A user can belong to multiple groups, view the user's group, gourps + username
[hadoop@mxhost1 ~]$ groups hadoop
hadoop : hadoop
[hadoop@mxhost1 ~]$
Change the file linux directory \ file owner permissions
1. Change the file owner (chown)
[Root @ linux ~] # chown account name of the file or directory, as an owner of the file gongfuyujia.mp4 into hadoop
2. Change user group file with the command chgrp
[Root @ linux ~] # chgrp group file or directory name
3. In addition, you can also modify users and groups through the chown command, chown owner, owning group file \ directory name
4. covering Directory Permissions
For the following directory permissions to modify the default just modify the current level permissions. If subdirectories recursively also need to add parameters R
.
5. The Chown -R & lt: recursively together with all files in the subdirectory, directory
Reference text:
Linux each user must belong to a group, outside the group do not operate independently. In linux each file has, where the group concept of an owner other groups
- owner
- 所在组
- 其它组
- 改变用户所在的组
所有者
一般为文件的创建者,谁创建了该文件,就天然的成为该文件的所有者
用ls ‐ahl命令可以看到文件的所有者
也可以使用chown 用户名 文件名来修改文件的所有者
文件所在组
当某个用户创建了一个文件后,这个文件的所在组就是该用户所在的组
用ls ‐ahl命令可以看到文件的所有组
也可以使用chgrp 组名 文件名来修改文件所在的组
其它组
除开文件的所有者和所在组的用户外,系统的其它用户都是文件的其它组
文件权限
ls -l中显示的内容如下:
1
|
-rwxrw-r‐-1 root root 1213 Feb 2 09:39 abc
|
- 第一个字符代表文件(-)、目录(d),链接(l)- 10个字符确定不同用户能对文件干什么
- 其余字符每3个一组(rwx),读(r)、写(w)、执行(x)
- 第一组rwx:文件所有者的权限是读、写和执行
- 第二组rw-:与文件所有者同一组的用户的权限是读、写但不能执行
- 第三组r--:不与文件所有者同组的其他用户的权限是读不能写和执行
也可用数字表示为:r=4,w=2,x=1 因此rwx=4+2+1=7
- 1 表示连接的文件数
- root 表示用户
- root表示用户所在的组
- 1213 表示文件大小(字节)
- Feb 2 09:39 表示最后修改日期
- abc 表示文件名
改变权限的命令
chmod 改变文件或目录的权限
chmod 755 abc:赋予abc权限rwxr-xr-x
chmod u=rwx,g=rx,o=rx abc:同上u=用户权限,g=组权限,o=不同组其他用户权限
chmod u-x,g+w abc:给abc去除用户执行的权限,增加组写的权限
chmod a+r abc:给所有用户添加读的权限
查看用户和组
1.首先对于经验操作之前,我们先看下当前系统下的用户和组。whoami 查看当前登陆用户
[hadoop@mxhost1 ~]$ whoami
root
[hadoop@mxhost1 ~]$
2.Passwd文件存储当前系统所有用户,而组文件/etc/group记录。
3.一个用户可以属于多个组,查看用户所属的组,gourps + 用户名
[hadoop@mxhost1 ~]$ groups hadoop
hadoop : hadoop
[hadoop@mxhost1 ~]$
更改linux文件目录\文件拥有者权限
1.更改文件拥有者 (chown )
[root@linux ~]# chown 账号名称 文件或目录 ,如图把文件gongfuyujia.mp4的所属者改成hadoop
2.改变文件的用户组用命令 chgrp
[root@linux ~]# chgrp 组名 文件或目录
3.此外还可以通过chown命令同时修改用户和组, chown 所有者,所属组 文件\目录名
4.覆盖目录权限
对于目录权限修改之后,默认只是修改当前级别的权限。如果子目录也要递归需要加R参数
.
5.Chown -R : 进行递归,连同子目录下的所有文件、目录
参考原文: