Linux下的基础命令(5)
一、权限
1、chmod命令
作用:修改文件的权限
语法:
chmod 【选项】 {u、g、o、a} {+-=} 文件名
解析:
u:所有者权限
g:所属组
o:其他人
a:所有
+:添加
-:减少
=:直接给定
-R:递归修改权限
权限:
r:可读
w:可写
x:可执行
#添加x权限 [root@rhel8 data]# chmod u+x a.txt [root@rhel8 data]# ll total 0 -rwxr--r--. 1 root root 0 Jan 4 20:10 a.txt #减少权限 [root@rhel8 data]# chmod o-r a.txt [root@rhel8 data]# ll a.txt -rwxr-----. 1 root root 0 Jan 4 20:10 a.txt #递归修改权限 [root@rhel8 data]# mkdir abc [root@rhel8 data]# ll -d abc/ drwxr-xr-x. 2 root root 6 Jan 4 20:17 abc/ [root@rhel8 data]# touch abc/b.txt [root@rhel8 data]# ll abc/b.txt -rw-r--r--. 1 root root 0 Jan 4 20:18 abc/b.txt [root@rhel8 data]# ll -d abc/ drwxrwxrwx. 2 root root 19 Jan 4 20:18 abc/ [root@rhel8 data]# ll abc/b.txt -rwxrwxrwx. 1 root root 0 Jan 4 20:18 abc/b.txt
2、chown命令
作用:修改文件/目录的所有者和所属组
语法:
chown root:root 文件名
选项:
-R:递归修改所属主和所属组
#修改所有者或者所属组 [root@rhel8 data]# ll a.txt -rwxr-----. 1 root root 0 Jan 4 20:10 a.txt [root@rhel8 data]# chown lisi:lisi a.txt [root@rhel8 data]# ll a.txt -rwxr-----. 1 lisi lisi 0 Jan 4 20:10 a.txt #递归修改 [root@rhel8 data]# ll -d abc/ drwxrwxrwx. 2 root root 19 Jan 4 20:18 abc/ [root@rhel8 data]# chown -R :zhangsan abc/ [root@rhel8 data]# ll -d abc/ abc/b.txt drwxrwxrwx. 2 root zhangsan 19 Jan 4 20:18 abc/ -rwxrwxrwx. 1 root zhangsan 0 Jan 4 20:18 abc/b.txt
3、特殊权-SGID
SGID:
作用:设置这个SGID,新创建的文件的属组都是设定的基本组
如果文件有执行权限:则显示的s
如果文件没有执行权限x,则显示S
#创建一个王五用户,切换到他的家目录 [wangwu@rhel8 home]$ chmod 755 wangwu [wangwu@rhel8 home]$ ll -d wangwu/ drwxr-xr-x. 3 wangwu wangwu 78 Jan 4 20:30 wangwu/ #设置SGID-->如果原来有执行权限,则设置SGID就会显示s [wangwu@rhel8 home]$ chmod g+s wangwu/ [wangwu@rhel8 home]$ ll -d wangwu/ drwxr-sr-x. 3 wangwu wangwu 78 Jan 4 20:30 wangwu/ #如果没有执行权限,设置SGID权限,则显示大S [wangwu@rhel8 home]$ chmod 745 wangwu/ [wangwu@rhel8 home]$ ll -d wangwu/ drwxr-Sr-x. 3 wangwu wangwu 78 Jan 4 20:30 wangwu/ #使用root创建文件,所属组自动会变成王五的 [root@rhel8 ~]# cd /home/wangwu/ [root@rhel8 wangwu]# touch a.txt [root@rhel8 wangwu]# ll a.txt -rw-r--r--. 1 root wangwu 0 Jan 4 20:36 a.txt #如果创建目录,然而SGID的权限也会继承 [root@rhel8 wangwu]# mkdir mulu [root@rhel8 wangwu]# ll -ld mulu/ drwxr-sr-x. 2 root wangwu 6 Jan 4 20:36 mulu/
4、文件的访问控制列表ACL
setfacl命令
作用:设置ACL访问控制列表
语法:
setfacl 【选项】 {u、g、} :用户名:{r、w、x } 文件名
选项:
-m:修改acl权限
-x:删除一条acl规则
-b:清空所有
#为文件添加acl,使得zhangsan对文件有读和执行权限 +号代表就是有ACL权限在 [root@rhel8 data]# ll b.txt -rw-r--r--. 1 root root 0 Jan 4 20:46 b.txt [root@rhel8 data]# setfacl -m u:zhangsan:rx b.txt [root@rhel8 data]# ll b.txt -rw-r-xr--+ 1 root root 0 Jan 4 20:46 b.txt #为文件添加lisi这个组,使其可以读写执行,对于b.txt [root@rhel8 data]# setfacl -m g:lisi:rwx b.txt [root@rhel8 data]# ll b.txt -rw-rwxr--+ 1 root root 0 Jan 4 20:46 b.txt #删除一条facl权限 [root@rhel8 data]# setfacl -x u:zhangsan b.txt [root@rhel8 data]# getfacl b.txt #清空所有的acl权限 [root@rhel8 data]# setfacl -b b.txt [root@rhel8 data]# getfacl b.txt
getfacl命令
作用:查看访问控制列表
语法:
getfacl + 文件名
[root@rhel8 data]# setfacl -x u:zhangsan b.txt [root@rhel8 data]# getfacl b.txt # file: b.txt # owner: root # group: root user::rw- group::r-- group:lisi:rwx mask::rwx other::r--
二、链接讲解
1、软连接
相当于windows的快捷方式
可以跨文件系统,
命令是ln -s 源文件 目标文件
如果删除源文件,则链接文件无效
创建的软连接是满权限位置
2、硬链接
硬链接是无法跨分区创建的
命令是:ln 源文件 目标文件
i节点和源文件相同
3、软硬连接的练习
#创建一个文件 [root@rhel8 data]# touch aa [root@rhel8 data]# ll aa -rw-r--r--. 1 root root 0 Jan 4 20:57 aa #分别创建软连接和硬链接 [root@rhel8 data]# ln -s /data/aa aa.soft [root@rhel8 data]# ln /data/aa aa.hard [root@rhel8 data]# ll total 0 -rw-r--r--. 2 root root 0 Jan 4 20:57 aa -rw-r--r--. 2 root root 0 Jan 4 20:57 aa.hard lrwxrwxrwx. 1 root root 8 Jan 4 20:59 aa.soft -> /data/aa #删除源文件后软连接会闪烁,硬链接则没有影响 -rw-r--r--. 1 root root 0 Jan 4 20:57 aa.hard lrwxrwxrwx. 1 root root 8 Jan 4 20:59 aa.soft -> /data/aa
三、软件包管理
作用:管理rpm包
语法:
rpm 【选项】 软件包
选项:
-q:查询包
-qi:查询已安装包的信息
-qa:查询系统所有的安装的包
-ivh:安装软件包-->不会自动解决依赖关系
-Uvh:升级软件包
-e:卸载软件包
-qf:查看文件是从哪个软件包安装的
-ql:查看帮助文档
#查询是否安装了nginx [root@rhel8 data]# rpm -qa nginx #查看软件的配置文档 [root@rhel8 ~]# rpm -ql libksba-1.3.5-7.el8.x86_64 #查看文件是从哪个软件包过来的 [root@rhel8 ~]# rpm -qf /usr/bin/ls coreutils-8.30-6.el8.x86_64 #安装 直接报错,-->不会自动解决依赖关系 [root@rhel8 ~]# rpm -ivh /mnt/AppStream/Packages/nginx-1.14.1-8.module+el8+2505+fe936cef.x86_64.rpm warning: /mnt/AppStream/Packages/nginx-1.14.1-8.module+el8+2505+fe936cef.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY error: Failed dependencies: nginx-all-modules = 1:1.14.1-8.module+el8+2505+fe936cef is needed by nginx-1:1.14.1-8.module+el8+2505+fe936cef.x86_64 nginx-filesystem is needed by nginx-1:1.14.1-8.module+el8+2505+fe936cef.x86_64 nginx-filesystem = 1:1.14.1-8.module+el8+2505+fe936cef is needed by nginx-1:1.14.1-8.module+el8+2505+fe936cef.x86_64
2、Centos8 搭建本地yum源
#修改配置文件 [root@rhel8 data]# vim /etc/yum.repos.d/local.repo [BaseOS] name=BaseOS baseurl=file:///mnt/cdrom/BaseOS enabled=1 gpgcheck=0 [AppStream] name=AppStream baseurl=file:///mnt/cdrom/AppStream enabled=1 gpgcheck=0 #挂载光盘 [root@rhel8 ~]# mount /dev/cdrom /mnt/ mount: /mnt: /dev/sr0 already mounted on /run/media/root/RHEL-8-0-0-BaseOS-x86_64. #测试 [root@rhel8 ~]# dnf repolist all
3、dnf命令
常用:
dnf repolist all :查看所有的可用软件
dnf list 软件名 :所有指定的软件
dnf install 软件名:安装
dnf clean all:清除所有的源
dnf remove 软件包 :卸载软件包,尽量不要用,它会自动卸载对应的依赖,导致其他的服务使用不了
dnf provides 软件 :查看软件由哪个包提供
#安装 [root@rhel8 ~]# dnf -y install nginx #查询 [root@rhel8 ~]# dnf list nginx #查询包的详细信息 [root@rhel8 ~]# dnf info nginx #查看软件是由那个包提供的 [root@rhel8 ~]# dnf provides nginx
持之以恒&静心定性

浙公网安备 33010602011771号