Linux组
- Linux中的每个用户必须属于一个组,不能独立于组外。在Linux中每个文件有所属用户、所在组的概念;
- 所属者:这个文件是哪个用户的;一般为文件的创建者,
- 所在组:这个文件所在的组;
查看路径下文件信息
- 查看文件的所属者:ls -ahl
- 示例:创建一个police组的用户tom,用tom创建一个文件 tom.txt
[root@ming ~]# groudadd police
bash: groudadd: 未找到命令...
[root@ming ~]# groupadd police
[root@ming ~]# usradd -g police tom
bash: usradd: 未找到命令...
[root@ming ~]# useradd -g police tom
[root@ming ~]# su tom
[tom@ming ~]$ cd //这里切换到tom的home目录,不然创建tom.txt权限不够
[tom@ming ~]$ touch tom.txt
[tom@ming ~]$ ls -ahl
总用量 16K
drwx------. 5 tom police 143 3月 4 15:37 .
drwxr-xr-x. 7 root root 77 3月 4 15:32 ..
-rw-------. 1 tom police 27 3月 4 15:33 .bash_history
-rw-r--r--. 1 tom police 18 8月 8 2019 .bash_logout
-rw-r--r--. 1 tom police 193 8月 8 2019 .bash_profile
-rw-r--r--. 1 tom police 231 8月 8 2019 .bashrc
drwxr-xr-x. 3 tom police 18 3月 4 15:33 .cache
drwxr-xr-x. 3 tom police 18 3月 4 15:33 .config
drwxr-xr-x. 4 tom police 39 2月 28 15:01 .mozilla
-rw-r--r--. 1 tom police 0 3月 4 15:37 tom.txt //新创建的文件
- 示例中,tom.txt的所属者为tom,tom.txt的所属组即为用户tom的所在组police;
修改文件所属用户
- chown 【用户名】 【文件名】
- -r 表示将文件及其子文件递归修改到用户名下
- 示例:root用户创建文件 apple.txt,然后将该文件转到tom名下
[root@ming ~]# touch apple.txt
[root@ming ~]# ll
总用量 4
-rw-------. 1 root root 1240 2月 28 22:23 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 3月 4 15:46 apple.txt
[root@ming ~]# chown tom apple.txt
[root@ming ~]# ll
总用量 4
-rw-------. 1 root root 1240 2月 28 22:23 anaconda-ks.cfg
-rw-r--r--. 1 tom root 0 3月 4 15:46 apple.txt
- 在上面的示例中,可以看到,文件的所在组发生了变,但文件的位置仍然在root用户的home目录下;
修改文件所属组
- chgrp 【组名】 【文件名】
- 示例:root用户创建文件 apple.txt,然后将该文件转到police组下
[root@ming ~]# chgrp police apple.txt
[root@ming ~]# ll
总用量 4
-rw-------. 1 root root 1240 2月 28 22:23 anaconda-ks.cfg
-rw-r--r--. 1 tom police 0 3月 4 15:46 apple.txt
- 上面的示例中,第0个字符表示文件的类型,有以下5种
普通文件 :-;
目录文件:d;
软链接文件:l;
字符设备,如键盘鼠标等:c;
块文件:b;
- 第1-3个字符表示所属用户的权限;如rw-,这说明所属用户可读可写,但不可执行
- 第4-6个字符表示所在组用户的权限;如上示例中的r–,表示所在组用户只能读;
- 第7-9个字符表示其它组用户的权限;
r为可读,read的简写;
w为可写,write的简写,有可读权限的人才能删除该文件;
x为可执行;
- tom前的1,如果该文件是硬链接的数,如果是目录,则表示该目录的子目录个数;
- 上示例中,apple.txt的文件大小为0,表示这个文件里为内容为0个字节;
- 示例中的时间,这最后修改该文件的时间