目录

权限就是用户可以对文件可以进行的操作,例如:可读,可写,可执行
chmod
 -c : 若该文件权限确实已经更改,才显示其更改动作
 -f :若该文件权限无法被更改也不要显示错误讯息
 -v :显示权限变更的详细资料
 -R :对目前目录下的所有文件与子目录进行相同的权限变更(即以递归的方式逐个变更)
 u-属主(Owner)、g-属组(Group)、o-其他使用者(Other Users)
 

+号就可以添加权限,-号代表取消权限,=代表唯一设定权限功能一览表:
Operator  | 说明  | 
|---|---|
+  | 为指定的用户类型增加权限  | 
-  | 去除指定用户类型的权限  | 
=  | 设置指定用户权限的设置,即将用户类型的所有权限重新设置  | 
模式  | 对应数字  | 描述  | 
|---|---|---|
r  | 4  | 设置为可读权限  | 
w  | 2  | 设置为可写权限  | 
x  | 1  | 设置为可执行权限  | 
**设置最小权限使文件执行相应的操作**
umask值相减,遇到奇数加一,遇到偶数则不变[root@localhost ~]# cat /etc/profile
root用户举例,示例如下:
# 查看uid
[root@localhost ~]# id root
uid=0(root) gid=0(root) groups=0(root)
# uid <199,第一步为假了
[root@localhost test]# /usr/bin/id -gn
root
[root@localhost test]# /usr/bin/id -un
root
# 执行结果相同,为真
# False && True = False,所以root的umask = 022
# 那么我们在root用户下创建的用户默认权限就可以计算了,文件权限666和目录权限777与umask相减来验证
# 1、文件默认权限验证
666的每位与022相减: 
6-0 =6   # 偶数不用变
6-2 =4   # 偶数不用变
6-2 = 4  # 偶数不用变
# 所以root下创建文件的默认权限为644---->rw-r--r--
# 实际创建验证
[root@localhost test]# touch a.txt
[root@localhost test]# ll -i
total 0
1423023 -rw-r--r--. 1 root root 0 Dec 15 15:48 a.txt
# 2、目录默认权限验证
777的每位与022直接相减,不需要判断奇偶
7 - 0 = 7
7 - 2 = 5
7 - 2 = 5
# 所以root下创建的目录的默认权限为755 ----> rwxr-xr-x
# 实际创建验证
[root@localhost ~]# mkdir test
[root@localhost ~]# ll -i
1423022 drwxr-xr-x. 2 root root   19 Dec 15 15:48 test案例:a.txt为例,修改文件ugo的权限
[root@localhost test]# ll -ia
1423023 -rw-r--r--. 1 root root   0 Dec 15 15:48 a.txt
# 现在ugo的权限为读写,可读,可读,把ugo的权限扩大,改为读写执行
[root@localhost test]# chmod ugo+rwx a.txt 
			或
[root@localhost test]# chmod 777 a.txt
[root@localhost test]# ll -i
total 0
1423023 -rwxrwxrwx. 1 root root 0 Dec 15 15:48 a.txt
# 将a.txt ugo的读写执行权限都去掉
[root@localhost test]# chmod ugo-rwx a.txt 
			或
[root@localhost test]# chmod -777 a.txt 
[root@localhost test]# ll -i
total 0
1423023 ----------. 1 root root 0 Dec 15 15:48 a.txt
# 分别给a.txt 的u读写执行,g添加读写,o添加读权限
[root@localhost test]# chmod u+rwx,g+rw,o+r a.txt 
		或
[root@localhost test]# chmod 764 a.txt 
[root@localhost test]# ll -i
total 0
1423023 -rwxrw-r--. 1 root root 0 Dec 15 15:48 a.txt
# 分别给a.txt 的u读写,g执行,o没有任何权限
[root@localhost test]# chmod u+rw,g+x a.txt 
		或
[root@localhost test]# chmod 610 a.txt 
[root@localhost test]# ll -i
total 0
1423023 -rw---x---. 1 root root 0 Dec 15 15:48 a.txt案例:以test文件夹为例,分配权限
# 查看test文件夹文件的权限
[root@localhost test]# ll
total 0
----------. 1 root root 0 Dec 15 15:48 a.txt
----------. 1 root root 0 Dec 15 16:25 b.txt
# 没有任何权限,下面给test文件下的所有文件添加读写执行权限
[root@localhost ~]# chmod -R 777 test 
[root@localhost ~]# ll test
total 0
-rwxrwxrwx. 1 root root 0 Dec 15 15:48 a.txt
-rwxrwxrwx. 1 root root 0 Dec 15 16:25 b.txt
# 将test目录下所有文件的属组的执行权限,其他使用者的写和执行权限去掉
[root@localhost ~]# chmod -R g-x,o-wx test/
[root@localhost ~]# ll test/
total 0
-rwxrw-r--. 1 root root 0 Dec 15 15:48 a.txt
-rwxrw-r--. 1 root root 0 Dec 15 16:25 b.txtps:若用 chmod 4755 filename 可使此程序具有 root 的权限。
useradd [用户名]
 passwd [用户名]
 echo [密码]|passwd --stdin [用户名] (一般用在脚本文件中)su 和 su -
 su是切换用户,但是切换后的用户缺少相应的文件或环境变量;su -相当于重新登录,切换后的用户携带环境变量或相应文件pwd和echo $PATH两个命令查看超管和普通用户切换后的区别用户切换原理图:

echo $PS1命令修改显示命令行提示符格式信息临时切换提示
永久设置切换提示
/etc/profile export PS1='[\u@\h \w]\$ 'sourcesource /etc/profile,设置成功+【待续】