liunx exercise

云计算作业

Linux

DAY1
1、创建alan1用户,并使用root'用户切换用户至alan1用户。(两种方式切换【加-与不加-】,并总结其效果)
[root@localhost ~]# useradd alan1
[root@localhost ~]# su alan1
[alan1@localhost root]$ pwd
/root
[alan1@localhost root]$ exit
exit
[root@localhost ~]# su - alan1
上一次登录:三 8月  9 18:48:14 CST 2023pts/0 上
[alan1@localhost ~]$ pwd
/home/alan1
[alan1@localhost ~]$ #su 切换用户时,改变登录的用户名,不改变其家目录;su - 切换到普通用户时,不仅改变用户名,还改变了它所在的家目录
​

2、(预习看效果)查看本地时间,要求只显示分钟、小时、秒

[alan1@localhost ~]$ #2.显示当前时间时分秒
[root@localhost ~]# date +%X
10时22分59秒
​

3、查看/root下的文件信息,分别简单显示、人性化显示、详细显示以及显示隐藏文件。

[root@localhost ~]# #简单显示ls,人性化显示ll -h,详细显示ll ,隐藏文件ls -a
[root@localhost ~]# ls /root
1.txt  a  anaconda-ks.cfg  b  c  qianfeng
[root@localhost ~]# ll -h /root
总用量 4.0K
-rw-r--r--. 1 root root    0 8月   8 18:31 1.txt
-rw-r--r--. 1 root root    0 8月   8 13:48 a
-rw-------. 1 root root 1.3K 8月   8 11:38 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 8月   8 13:48 b
-rw-r--r--. 1 root root    0 8月   8 13:48 c
drwxr-xr-x. 3 root root   18 8月   8 18:31 qianfeng
[root@localhost ~]# ll /root
总用量 4
-rw-r--r--. 1 root root    0 8月   8 18:31 1.txt
-rw-r--r--. 1 root root    0 8月   8 13:48 a
-rw-------. 1 root root 1253 8月   8 11:38 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 8月   8 13:48 b
-rw-r--r--. 1 root root    0 8月   8 13:48 c
drwxr-xr-x. 3 root root   18 8月   8 18:31 qianfeng
[root@localhost ~]# ls -a /root
.   1.txt  anaconda-ks.cfg  .bash_history  .bash_profile  c       qianfeng
..  a      b                .bash_logout   .bashrc        .cshrc  .tcshrc
​
ls -d 显示当前文件夹的家目录 ll -d 查看当前文件的详细信息和家目录;
[root@localhost ~]# ls -a /home 
.  ..  alan1  tony1  tony2  tony3  tony4
[root@localhost ~]#  ls -ahl /home
总用量 0
drwxr-xr-x.  7 root  root   71 8月   9 18:48 .
dr-xr-xr-x. 17 root  root  224 8月   8 11:37 ..
drwx------.  2 alan1 alan1  83 8月   9 18:48 alan1
drwx------.  2 tony1 tony1  92 8月   9 16:55 tony1
drwx------.  2 tony2 tony2  83 8月   9 16:49 tony2
drwx------.  2  1002  1002  62 8月   9 11:10 tony3
drwx------.  2 tony4 tony4  62 8月   9 11:10 tony4
[root@localhost ~]# ls -ahld /home
drwxr-xr-x. 7 root root 71 8月   9 18:48 /home
​
​
​

4.Linux发行版有哪些?名字

中国:centOS
西方 ubantu
5.红帽认证是什么(搜百度)?
红帽认证[技师]/系统管理员(RHCSA),红帽认证[工程师](RHCE)和红帽认证[架构师](RHCA)
​
RHCA五门课程和考试
RHS333 Red Hat Enterprise Security: Network Services(安全:网络服务)
RH401 Red Hat Enterprise Deployment, Virtualization, and Systems Management(部署和系统管理员)
RH423 Red Hat Enterprise Directory Services and Authentication(目录服务和认证)
Clusterin英/ˈklʌstərɪŋ/集群
 Red Hat Enterprise Clustering and Storage Management(存储管理)
​
RH442 Red Hat Enterprise System Monitoring and Performance Tuning(系统监控和性能调整)

6.服务器的品牌有哪些?【中关村在线搜索】

超聚变,戴尔,浪潮,H3C,华为,惠普
1超聚变FusionServer 2288H价格面议
2戴尔易安信PowerEdge R740¥21397
3浪潮英信NF5280M6¥19399
4H3C UniServer R4900 G3(¥17099
5华为FusionServer RH2288H¥11987
6HP ProLiant DL380 Gen10(¥39800
7H3C UniServer R4900 G5价格面议
8超聚变FusionServer 2288H价格面议
9浪潮英信NF5280M5¥18300
10浪潮英信NF5270M6

7.找到CentOS官网进去查看一下。

8.安装一台centos虚拟机,要求该虚拟机安装成功后安装自动补全插件(bash-completion)。

yum -y install bash-completion
删除用户时,必须加-r,否则邮箱和家目录无法删除掉;当删除成功时显示提示信息加-v命令例如 rm -rfv
[root@localhost ~]# useradd heihei
[root@localhost ~]# ls /home
alan1  heihei  tony1  tony2  tony4
[root@localhost ~]# userdel heihei
[root@localhost ~]# ls /home
alan1  heihei  tony1  tony2  tony4
[root@localhost ~]# ls /var/spool/mail/
alan1  heihei  tony1  tony2  tony3  tony4
[root@localhost ~]# id heihei
id: heihei: no such user
[root@localhost ~]# rm -rf /home/heiehi
[root@localhost ~]# rm -rvf /var/spool/mail/heihei
已删除"/var/spool/mail/heihei"
​

DAY2
1.在/opt/test/dir1/test/目录下面创建20个test.txt文件

[root@localhost ~]# mkdir -p /opt/test/dir1/test ; touch /opt/test/dir1/test/test{1..20}.txt [root@localhost ~]# ls /opt/test/dir1/test/ test10.txt test14.txt test18.txt test2.txt test6.txt test11.txt test15.txt test19.txt test3.txt test7.txt test12.txt test16.txt test1.txt test4.txt test8.txt test13.txt test17.txt test20.txt test5.txt test9.txt

2.在/mnt/目录中创建dir2目录 [root@localhost ~]# mkdir -p /mnt/dir2 ; ls /mnt/ a A abc abcd.txt dir2 QF2307 tony.txt

3.将/opt/test/dir1/test/目录拷贝到/mnt/dir2目录中 [root@localhost ~]# rm -rf /mnt/* [root@localhost ~]# cp -rf /opt/test/dir1/test/ /mnt/dir2 ; ls /mnt/dir2 test13.txt test17.txt test20.txt test5.txt test9.txt test10.txt test14.txt test18.txt test2.txt test6.txt test11.txt test15.txt test19.txt test3.txt test7.txt test12.txt test16.txt test1.txt test4.txt test8.txt

4.将/mnt/dir2/目录中的test2.txt 改名为file300 mv /mnt/dir2/test2.txt /mnt/dir2/file300 ; ls /mnt/dir2 【后面的目录是更改后的名字】

file300 test12.txt test16.txt test1.txt test5.txt test9.txt test test13.txt test17.txt test20.txt test6.txt test10.txt test14.txt test18.txt test3.txt test7.txt test11.txt test15.txt test19.txt test4.txt test8.txt

5.将/mnt/dir2/目录中以txt结尾的文件删除。查看留下的文件 rm -rf /mnt/*txt ; ls /mnt/dir2/

[root@localhost ~]# rm -rf /mnt/dir2/*txt ; ls /mnt/dir2/ file300 test

1.若 file1 文件中有 1 行内容,file2 文件中有 3 行内容,执行完命令“cat < file1 > file2”后,file2

  • 1 行

2普通用户执行“ls -l /root > /tmp/test.txt”的结果是( )。

  • A显示/root 目录和/tmp/test.txt 文件信息

  • B显示/root 目录的详细列表,并重定向输出到/tmp/test.txt 文件

  • C将/root 目录的详细列表重定向到/tmp/test.txt,并报告错误

  • D报告错误信息

正确答案:D 普通用户没权限,无法查看;能够执行才能追加信息,前面不能执行,就会在页面上进行报错。

3。假设用户所使用的系统上有两块 IDE 硬盘,查询第二块硬盘的分区情况的命令为( )。
  • Afdisk -l /dev/hda1

  • Bfdisk -l /dev/had

  • Cfdisk -l /dev/hdb

  • Dfdisk -l /dev/hdb2

正确答案:C 软盘soft diak sd;硬盘hard disk hd 顺序依次为a...z

.4统计磁盘空间或文件系统使用情况的命令是( )。

  • Afdisk

  • Bdu

  • Cdd

  • Ddf

正确答案:A

/etc/fstab是用来存放文件系统的静态信息的文件。位于/etc/目录下,可以用命令less /etc/fstab 来查看,如果要修改的话,则用命令 vi /etc/fstab 来修改。

当系统启动的时候,系统会自动地从这个文件读取信息,并且会自动将此文件中指定的文件系统挂载到指定的目录。下面我来介绍如何在此文件下填写信息。

5.Linux 系统中文件系统的挂载配置文件是( )。

  • A/dev/sda

  • B/etc/profile

  • C/etc/passwd

  • D/etc/fstab

正确答案:D

.

.一、逻辑卷管理(LVM)概念 逻辑卷和逻辑卷管理有助于更加轻松地管理磁盘空间。 如果托管逻辑卷的文件系统需要更多空间可以将其卷组中的可用空间分配给逻辑卷,并且可以调整文件系统的大小。 如果磁盘开始出现错误,可以将替换磁盘注册为物理卷放入卷组中,并且逻辑卷的区块可迁移到新磁盘。

  1. LVM 定义 Logical Volume Manager 物理设备物理设备是用于保存逻辑卷中所存储数据的存储设备。 它们是块设备,可以是磁盘分区、整个磁盘、RAID 阵列或SAN 磁盘。 设备必须初始化为 LVM 物理卷,才能与 LVM 结合使用。整个设备将用作一个物理卷。

  2. 物理卷(PV) 物理卷是LVM 所使用的基础“物理”存储。在LVM 系统中使用设备之前,必须将设备初始化为物理卷。 LVM 工具会将物理卷划分为物理区块PE),它们是充当物理卷上最小存储块的小块数据。 组(VG) 卷组是存储池,由一个或多个物理卷组成。它在功能上与基本存储中的整个磁盘相当。一个 PV只能分配给一个 VG。VG 可以包含未使用的空间和任意数目的逻辑卷。 1

  3. 逻辑卷(LV) 逻辑卷根据券组中的空闲物理区块创建,提供应用、用户和操作系统所使用的“存储”设备。LV是逻辑区块(LE)的集合,LE 映射到物理区块 (PV的最小存储块)。 默认情况下,每个LE 将映射到一个 PE。设置特定 LV 选项将会更改此映射,例如,镜像会导致每个LE 映射到两个PE。

    物理分区或磁盘是 LVM 的第一构建块。这些可以是分区、完整磁盘、 RAID 集或 SAN 磁盘。
    物理卷(PV)是 LVM 所使用的基础 “物理 ”存储。这通常是块设备,例如分区或完整磁盘。设备必须初始化为LVM 物理卷 ,才能与 LVM 结合使用。
    物理卷组(VG)是存储池, 由一个或多个物理卷组成。
    物理区块(PE)是物理卷中存储的小型数据区块,用作 LVM 存储的后端。
    逻辑区块映射到物理区块 ,构成 LVM 存储的前端。默认情况下,每个逻辑区块映射到一个物理区块。启用某些选项将更改此映射。例如 , 镜像会导致每个逻辑区块映射到两个物理区块,逻辑卷是逻辑区块组。逻辑卷可以像硬盘驱动器分区一样使用。

    我们的物理分区就相当于橙子,有几个分区就有几个橙子,现在我们把两个橙子榨成汁,放入各自的杯子中,即物理卷,我们把两杯橙汁倒入一个大容器中,即物理卷组,我们每次拿一个小杯子喝,即逻辑卷,喝完了再从大杯子(物理卷组)里倒,大杯子(物理卷组)橙汁不够,我们再用橙子(物理分区)继续榨汁倒入大杯子就行

    二、创建逻辑卷

  4. pvcreate命令将分区标记为物理卷,创建物理卷pvcreate /dev/vdb1 /dev/vdb2

  5. vgcreate命令将一个或多个物理卷结合为一个卷组,创建卷组vgcreate servera_01_vg /dev/vdb1 /dev/vdb2

  6. lvcreate命令根据卷组中的可用物理区块,创建逻辑卷

    lvcreate -n 设置LV名称 lvcreate -L 设置LV大小(以字节为单位) lvcreate -l 设置LV大小(以区块数为单位)以及托管此逻辑卷的卷组的名称 lvcreate -n servera_01_lv -L 400M servera_01_vg

  1. mkfs 在新逻辑卷上创建XFS 文件系统。mkfs -t xfs /dev/servera_01_vg/servera_01_lv

  1. df -h命令显示磁盘文件的大小df -h /data 1

  2. 三、查看 LVM 状态信息

  3. pvdisplay 显示有关物理卷的信息pvdisplay /dev/vdb

  4. vgdisplay显示卷组的信息vgdisplay servera_01_vg

  1. lvdisplay 显示逻辑组的信息lvdisplay /dev/servera_01_vg/servera_01_lv

四、删除逻辑卷

  1. lvremoveDEVICENAME删除逻辑卷。Ivremove /dev/vg01/1v01

  2. vgremove 删除不再需要的卷组。vgremove vg01 VG的物理卷会被释放,并可用于分配给系统中的现有VG或新VG。

  3. pvremove删除物理卷pvremove /dev/vdb2 /dev/vdb1 用空格分隔的 PV设备列表同时删除多个PV。此命令将从分区(或磁盘) 中删除 PV 元数据。分区现已空闲,可重新分配或重新格式化。

( )命令可以将物理硬盘初始化为物理卷。

  • Avgcreate

  • Blvcreate

  • Cpvcreate

  • Dvgscan

正确答案:C

( )命令用来重定向管道的输出到标准输出和指定文件。
  • A tee B cat C less D wee

    正确答案:A

    ( )命令可在环境变量 PATH 设置的目录中查找符合条件的命令文件所在位置。

    • Awhich BWho C Ll D echo

    正确答案:A

    ( )命令可以让用户快速查找到所需要的文件或目录。

    • All Blocate CGrep DVgscan

    正确答案:B

    在使用 RPM 安装过程中,“--nodeps”参数表示( )。

    • A不检验软件包的签名

    • B重新或覆盖安装

    • C#NAME?

    • D忽略依赖关系

    正确答案:D Linux中no和un都表示取反;depend 依赖

    使用源码安装时,configure 后面的“--prefix”参数表示( )。

    • A指定安装路径

    • B启用或禁用某项功能

    • C和其他软件关联

    • D检测安装环境

    正确答案:A

    5.下列选项中,不属于官方源的是( )。

    • ANginx Bbase Cextras Dupdates

    正确答案:A

    6.查看 yum 源中是否存在可安装软件包的命令为( )。

    • Ayum install

    • Byum list

    • Cyum clean all

    • Dyum remove

    正确答案:B

    7.重新安装软件的命令为( )。

    • Ayum install

    • Byum list

    • Cyum clean all

    • Dyum remove

    正确答案:C

    8.查看文件所属的软件包的命令为( )。

  • Ayum info

  • Byum search

  • Cyum update

  • Dyum provides

正确答案:D

9.下列说法错误的是( )。

  • Ayum 不可以更改 yum 源

  • Byum 可以方便地实现软件包升级

  • Cyum 也是通过 RPM 包安装软件

  • Dyum 可以解决软件包依赖关系

正确答案:A

对文件进行打包的命令为( )。

  • Agzip

  • Bdump

  • Ctar

  • Ddd

正确答案:C

13.find 命令通过( )参数可以指定查找的目录深度。

  • AA.-itime

  • BB.-mtime

  • CC.-name

  • DD.-maxdepth

正确答案:D

14.find 命令按文件类型查找需要添加( )参数。

  • AA.-type

  • BB.-mtime

  • CC.-name

  • DD.-maxdepth

正确答案:A

15.查看系统版本信息的命令为( )。
  • Acat

  • BWho

  • Cll

  • Decho

正确答案:A

cat /etc/centos-release CentOS Linux release 7.4.1708 (Core)

( )是 UNIX 系统之间共享文件的一种协议。

NFS(Network File System)即网络文件系统

  • AHTTP

  • BTCP

  • C NFS

  • DIP

正确答案:C

()是以 CIFS 网络协议实现的一款软件。common Internet File System):通用网络文件系统

  • Alftp

  • Bftp

  • Cnfs

  • DSamba

正确答案:D

 samba的发展及由来
在早期的网络世界当中,文件数据在不同的主机之前的传输大多是使用FTP文件服务器,但是FTP无法直接修改Linux主机上的文件,需要将该文件从FTP服务器下载下来之后再去修改,所以该文件在服务器和客户端均会存在。

samba可以让Linux加入windows的网上邻居支持,既可以用于windows和Linux之间的文件共享,也可以用在于Linux和Linux之间的资源共享,不仅如此,samba也可以让Linux上面的打印机成为打印机服务器Printer Server。

服务名称    使用范围    服务端 客户端 局限性
FTP 局域网和公网  Windows & Linux Windows & Linux 无法直接修改服务端的文件
NFS 局域网和公网  Linux   Linux   只能在Linux之间使用
SAMBA   局域网 Windows & Linux Windows & Linux 只能在局域网中使用

()工具不可以从 FTP 服务器下载文件。

  • Aput

  • Bwget

  • Clftp

  • Dcurl

正确答案:A

.

()文件主要为本地主机名、集群节点提供快速解析。
  • A

    hosts

  • Bvsftpd

  • Chostname

  • D

    DNS

正确答案:A

5.()是 DNS 客户机配置文件。

  • A

    /etc/vsftpd/vsftpd.conf

  • B/etc/resolv.conf

  • C/etc/vsftpd/vsftpd

  • D/etc/resolv

正确答案:B

6.Linux 系统使用的 FTP 服务器软件为( )。
  • Avsftpd
  • Bnginx

  • Cftp

  • Dapache

正确答案:A

7.FTP 服务的主配置文件为( )。

  • A/etc/vsftpd/vsftpd

  • B/etc/vsftpd/vsftpd.conf

  • C/etc/vsftpd

  • D/vsftpd/vsftpd.conf

正确答案:B

DNS 软件的包名为( )。

  • ADNS

  • Bbind-chroot

  • Cbind

  • Dtcpdump

正确答案:C

在区域配置文件中,( )表示起始授权记录。
  • ASOA

  • BIN

  • CA

  • DNS

正确答案:A

Day3

1.将/etc/sysconfig/network-scripts/ifcfg-ens33 中的文件拷贝到opt目录下,并命名为ens32.bak

拷贝;移动改名;查看验证
[root@localhost ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens33 /opt
[root@localhost ~]# mv /opt/ifcfg-ens33  /opt/ens32.bak
[root@localhost ~]# cat /opt/ens32.bak 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="1234fbcc-0837-4a53-b31b-f563b6244f58"
DEVICE="ens33"
ONBOOT="yes"
​

查看尾部五行 和首行内容

tail -5 /etc/sysconfig/network-scripts/ifcfg-ens33 
 head -1 /etc/sysconfig/network-scripts/ifcfg-ens33
软连接和硬链接特点
创建链接时一定要写绝对路径;链接文件的权限最终取决于源文件的权限;
软连接:可以跨分区,可以对目录进行链接,源文件删除后,链接文件不可用;
硬链接:不可以跨分区,不可以对目录进行链接,源文件删除后,链接文件仍然可用,类似系统备份;
​

在/opt目录下创建hello2.hard wenjian ,并创建硬链接到/tmp目录下,并查看链接文件的详细属性;

touch  /opt/hello2.hard ; ln -r /opt/hello2.hard /tmp/ ; ll   -h /tmp
​

获取ls命令信息--which

#显示系统内核kernel信息-s内核名称-r内核版本
[root@localhost ~]# uname -rs
Linux 3.10.0-693.el7.x86_64
​
查看文档/etc/passwd 前11-13行内容
-n 显示行号;先查前13行,再从尾部查3行。
[root@localhost ~]# cat -n  /etc/passwd|head -13 |tail -3
    11  games:x:12:100:games:/usr/games:/sbin/nologin
    12  ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
    13  nobody:x:99:99:Nobody:/:/sbin/nologin
​
在/etc/fstab 文件中排除带#的注释行
-n行号输出-i忽略大小写 【-v排除内容】^开头$结尾 ^$匹配空行
​
​
[root@localhost ~]# grep -nv '^#' /etc/fstab
1:
9:/dev/mapper/centos-root /                       xfs     defaults        0 0
10:UUID=baa89337-7e24-471a-a5f5-df2fb86df9a1 /boot                   xfs     defaults        0 0
11:/dev/mapper/centos-swap swap                    swap    defaults        0 0
[root@localhost ~]# cat -n /etc/fstab 
     1  
     2  #
     3  # /etc/fstab
     4  # Created by anaconda on Tue Aug  8 11:35:32 2023
     5  #
     6  # Accessible filesystems, by reference, are maintained under '/dev/disk'
     7  # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
     8  #
     9  /dev/mapper/centos-root /                       xfs     defaults        0 0
    10  UUID=baa89337-7e24-471a-a5f5-df2fb86df9a1 /boot                   xfs     defaults        0 0
    11  /dev/mapper/centos-swap swap                    swap    defaults        0 0
​

创建用户 ;指定uid-u;指定家目录-d 指定详细信息 -c ;查看所有用户 cat /etc/passwd

[root@localhost ~]# useradd u01    【创建u01用户,其家目录时默认目录(家目录)】
[root@localhost ~]# useradd -u 1100 u02【指定u02用户的uid是1100】
[root@localhost ~]# useradd -d /root/u03 u03【指定u03用户的家目录是root/u03】
[root@localhost ~]# useradd -u 1052 -c yunwei u04【指定用户的uid是1052,并备注信息运维】
[root@localhost ~]# cat /etc/passwd  【存放用户信息文件】
【多余用户已删减】
u01:x:1006:1006::/home/u01:/bin/bash
u02:x:1100:1100::/home/u02:/bin/bash
u03:x:1101:1101::/root/u03:/bin/bash
u04:x:1052:1052:yunwei:/home/u04:/bin/bash
综合运用
​[root@localhost ~]# useradd -u 6666 -d /root/uncle1 -c yunwei yangailin
[root@localhost ~]# id yangailin
uid=6666(yangailin) gid=6666(yangailin) 组=6666(yangailin)
[root@localhost ~]# cat /etc/passwd |grep yangailin
yangailin:x:6666:6666:yunwei:/root/uncle1:/bin/bash

修改用户属性

usermod用于修改已存在的用户信息 
1.-u 修改用户的uid ,如果用户已登陆,不允许修改
root@localhost ~]# id root
uid=0(root) gid=0(root) 组=0(root)
[root@localhost ~]# usermod -u 1111 root
usermod: user root is currently used by process 1
[root@localhost ~]# usermod -u 9999 tony1
[root@localhost ~]# id tony1
uid=9999(tony1) gid=1004(tony1) 组=1004(tony1)
2.修改用户描述信息和附加组,家目录,
root@localhost ~]# usermod -c army  -G test -d root  tony1
[root@localhost ~]# id tony1
uid=9999(tony1) gid=1006(u01) 组=1006(u01),1102(test)
[root@localhost ~]# cat /etc/passwd
tony1:x:9999:1006:army:root:/bin/bash
​
​[root@localhost ~]# usermod -u 1991 -d in87 -c team -G test yangailin
[root@localhost ~]# id yangailin ;cat /etc/passwd |grep yangailin
uid=1991(yangailin) gid=6666(yangailin) 组=6666(yangailin),1102(test)
yangailin:x:1991:6666:team:in87:/bin/bash

删除用户

删除用户-r 同时删除其家目录;

创建组;创建指定用户uid,描述信息基本组-g;附加组-G;指定用户的解释性程序-s 判断用户是否存在 id用户名

创建组 groupadd 组名 【删除组:groupdel 组名 】

groupadd yunweigongchengshi [添加一个名叫运维工程师的组]
# useradd -u 1666 -c yunwei05 -g test u05【创建用户并指定用户uid】
[root@localhost ~]# useradd -u 1777 -c yunwei06 -G test sixthuser【创建用户并指定用户uid描述信息和附加组】
[root@localhost ~]# useradd -u 1707 -c seven  -s /sbin/nologin u07【设置用户一个解释性程序】
​
[root@localhost ~]# id u05 ; id sixthuser ;id u07 【查看用户uid,基本组,附加组】
uid=1666(u05) gid=1102(test) 组=1102(test)
uid=1777(sixthuser) gid=1777(sixthuser) 组=1777(sixthuser),1102(test)
uid=1707(u07) gid=1707(u07) 组=1707(u07)
​
[root@localhost ~]# cat /etc/passwd  【查看用户权限】
u05:x:1666:1102:yunwei05:/home/u05:/bin/bash
sixthuser:x:1777:1777:yunwei06:/home/sixthuser:/bin/bash
u07:x:1707:1707:seven:/home/u07:/sbin/nologin
​

添加新组

groupadd 【-g 组id  】组名
[root@localhost ~]# groupadd -g 1000 team1
[root@localhost ~]# cat /etc/group
​

修改组属性

groupmod 【-g gid  /  -n 新组名】 组名
[root@localhost ~]# groupmod -g 7777 -n TONY test
​
查看组 
cat /etc/group

gpasswd.组添加删除成员

添加组和成员;将成员添加到组中;
[root@localhost ~]# groupadd redhat ; useradd rh1 ; useradd rh2 ;useradd rh3;gpasswd -a rh1 redhat ; gpasswd -a rh2 redhat ; gpasswd -a rh3 redhat; grep 'redhat' /etc/group
正在将用户“rh1”加入到“redhat”组中
正在将用户“rh2”加入到“redhat”组中
正在将用户“rh3”加入到“redhat”组中
redhat:x:10007:rh1,rh2,rh3
【-a 添加 -d 移除组员紧跟gpasswd,不可以变换位置,必须放到用户名之前,否则删不掉】
[root@localhost ~]# gpasswd -d rh1 redhat; grep 'redhat' /etc/group
正在将用户“rh1”从“redhat”组中删除
redhat:x:10007:rh2,rh3
​

权限

使用逗号可以为多个用户授权或者删除权限
chmod g+x,o-x 普通文件
目录文档权限添加删除
root@localhost ~]# mkdir /redhat ;ll -d /redhat
drwxr-xr-x. 2 root root 6 8月  12 20:15 /redhat
​
[root@localhost ~]# chmod g+w,o+w /redhat ;ll -d /redhat  【文档拥有者,所属组,其他人进行权限设置】
drwxrwxrwx. 2 root root 6 8月  12 20:15 /redhat
[root@localhost ~]# chmod u-x,g-w,o-w /redhat ; ll -d /redhat
drw-r-xr-x. 2 root root 6 8月  12 20:15 /redha
递归修改目录下所有子文件与子目录的权限
[root@localhost ~]# touch /home/hary/1.txt ;chmod -R 775 /home ;ll /home/hary/1.txt
-rwxrwxr-x. 1 root root 0 8月  12 20:42 /home/hary/1.txt
普通用户对该目录如果有rwx权限,是可以删除目录下任何用户创建的文件包括root
[root@localhost ~]# cd /home/tom
[root@localhost tom]#  rm -rf /home/hary/1.txt
[root@localhost tom]# ls /home/hary
用户对目录具有rwx权限: 查看目录下内容;在该目录下创建文件,修改属性,删除任何用户的文件;
用户对普通文件有rwx权限: 查看文件内容;可以运行该文件;能够对文档内容具有增删改权限,【不能删除文件本身,文件是否能删除取决于其所在的目录有没有rwx权限】
Day4
查找/etc/目录下以.conf结尾的文件【当前此层目录/所有子目录】
ls /etc/*.conf
find /etc/   -name   "*.conf"

vim不可以使用【安装/验证】

yum -y install vim*
[root@localhost ~]# rpm -qa|grep vim
vim-common-7.4.629-8.el7_9.x86_64
vim-X11-7.4.629-8.el7_9.x86_64
vim-enhanced-7.4.629-8.el7_9.x86_64
vim-filesystem-7.4.629-8.el7_9.x86_64
vim-minimal-7.4.629-8.el7_9.x86_64
​
单引号,双引号,反引号,不加引号的区别;
不加引号:字符串原样输出,变量会被替换。(根双引号一样,唯一的不同在于 \ 和 空格);双引号:里面的特殊符号会被解析,变量也会被替换(\ 符号、空格会被解析)
[root@localhost ~]# echo \a 1 2              【不叫单引号或双引号,\和空格会被解析】
a 1 2
[root@localhost ~]# echo  "\a 1             2"【原文输出】
\a 1             2
​
单引号:引号里面的内容会原封不动的显示出来(很简单,不做解释)【和双引号功效一样】
[root@localhost ~]# echo '\a 1 2'   '\a 1       3'
\a 1 2 \a 1       3
​
反引号:用于显示命令执行结果
 echo `date`   /a                     【不加引号反斜杠\ 会被解析;斜杠/不会被解析】
2023年 08月 13日 星期日 16:01:45 CST /a   
​

fd【file descriptors 文档描述,文件句柄】进程使用文件描述来打开文件

standard  标准
0: stdin[键盘输入] 1:[显stdout示屏正确输出] 2.【stderr错误输出】4
句柄结果执行覆盖/追加
[root@localhost ~]# ls /root/
1.txt  qianfeng  u03
[root@localhost ~]# ls 2.txt 2> 1.txt 【错误输出才会追加到1.txt文件中;保存错误提示信息】
[root@localhost ~]# cat 1.txt
ls: 无法访问2.txt: 没有那个文件或目录
[root@localhost ~]# ls 1.txt 1>1.txt   【正确输出的内容追加到1.txt中】
[root@localhost ~]# cat 1.txt
1.txt
错误的信息进行追加
[root@localhost ~]# ls 2.txt 2>>  1.txt
[root@localhost ~]# ls 2.txt 2>>  1.txt
[root@localhost ~]# ls 2.txt 2>>  1.txt
[root@localhost ~]# cat 1.txt
ls: 无法访问2.txt: 没有那个文件或目录
ls: 无法访问2.txt: 没有那个文件或目录
ls: 无法访问2.txt: 没有那个文件或目录
ls: 无法访问2.txt: 没有那个文件或目录
同时多个查询【】
[root@localhost ~]# ls 1.txt 11.txt 1> 1.txt
ls: 无法访问11.txt: 没有那个文件或目录
[root@localhost ~]# cat 1.txt   【1>多个查询时把正确内容追加到文档里,错误信息页面显示】
1.txt
[root@localhost ~]# ls 1.txt 11.txt 2> 1.txt
1.txt
[root@localhost ~]# cat 1.txt【2>多个查询时把错误内容追加到文档里,正确信息页面显示】
ls: 无法访问11.txt: 没有那个文件或目录
无论对错我都不想要查询的信息【&>】 存储到黑洞文件/dev/null
[root@localhost ~]# ls 1.txt 2.txt &> /dev/null
[root@localhost ~]# cat 1.txt ;cat2.txt
ls: 无法访问11.txt: 没有那个文件或目录
-bash: cat2.txt: 未找到命令
无论对错我都把执行结果覆盖到一个文件中【页面不提示,正确和错误信息都存储】
[root@localhost ~]# ls 1.txt 2.txt &> 1.txt
[root@localhost ~]# cat 1.txt
ls: 无法访问2.txt: 没有那个文件或目录
1.txt
​
输入重定向【把右侧内容作为输出条件的一部分】原理:利用输入重定向,把文件内容代替认为的输入
mail -s "root to tom de mail-subject-no"  tom < mail.txt 【把mail内容从当前用户root发送给Tom,主题是“root to tom de mail-subeject-no",此时命令可以发送多个人和多次 】
​
​
​
​

|管道符piping【前面的输出作为后面的输入,依次递进】

查看后三行用户信息
[root@localhost ~]# cat /etc/passwd |tail -3
saslauth:x:997:76:Saslauthd user:/run/saslauthd:/sbin/nologin
mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
查看以root开头的用户信息
[root@localhost ~]# cat /etc/passwd | grep ^root
root:x:0:0:root:/root:/bin/bash
统计用户信息有多少条
[root@localhost ~]# cat /etc/passwd | wc -l
45
统计远程链接有多少条
[root@localhost ~]# ps aux | grep ssh |wc -l
4
三通管道【tee,把查询的内容存储到文档里】和统计参数【Word Count 字符统计】
wc filename
第一列显示行数,第二列显示单词数,第三列显示字符数。【UTF-8编码中,一个英文字符等于一个字节,一个中文(含繁体)等于三个字节。】
wc 有四个参数可选,分别是l,c,m,w
wc -l filename 报告行数
wc -c filename 报告字节数
wc -m filename 报告字符数
wc -w filename 报告单词数
[root@localhost ~]# ps aux | tee  /home/2.txt |grep ssh |wc -l
4
[root@localhost ~]# cat /home/2.txt
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.3 128212  6856 ?        Ss   15:28   0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
root          2  0.0  0.0      0     0 ?        S    15:28   0:00 [kthreadd]

xargs (英文全拼: eXtended ARGuments)是给命令传递参数的一个过滤器,主要是由于很多命令不支持管道符号 | 来传递参数,在 Linux 的 Shell 命令中,诸如mkdircatrm , echo` 等命令都不支持直接将管道符的输出当做输入进而作为他们的操作对象来使用

[root@localhost ~]# echo helloworld | echo  【无输出】
[root@localhost ~]# echo helloworld | xargs echo
helloworld
【参数xargs使用位置管道符|之后】,实现效果和命令mkdir {1..4} 效果一致
[root@localhost ~]# echo {1..4} | mkdir
mkdir: 缺少操作数
Try 'mkdir --help' for more information.
[root@localhost ~]# echo {1..4} |  xargs  mkdir
[root@localhost ~]# ll .
总用量 0
drwxr-xr-x. 2 root root 6 8月  13 19:48 1
drwxr-xr-x. 2 root root 6 8月  13 19:48 2
drwxr-xr-x. 2 root root 6 8月  13 19:48 3
drwxr-xr-x. 2 root root 6 8月  13 19:48 4
在 Linux 中,有一些特殊字符需要进行转义才能正确地使用。下面是一些常见的需要进行转义的字符:
反斜杠(\):用于转义其他字符。
单引号(')和双引号("):用于引用字符串。如果字符串本身包含引号,则需要使用转义字符来确保引号被正确处理。
空格( ):用于分隔命令行参数。如果需要使用包含空格的文件或目录名,可以使用反斜杠进行转义,或者将其放在引号中。
美元符号($):在某些情况下,需要对美元符号进行转义,以避免被 Shell 解释为变量替换。
百分号(%):在某些上下文中,需要对百分号进行转义。
ampersand(&):在一些情况下,需要对 ampersand 进行转义,以防止其被解释为后台任务运行符。
重定向符号(<、>、|):在某些情况下,这些特殊符号需要进行转义,以防止它们被 Shell 解释为输入、输出重定向或管道操作符。
"\"转义符,配合-e解释转义字符;-d更改参数分隔符
以:进行参数分割
[root@localhost ~]# cat /etc/passwd | grep 'root' | head -1 | xargs -d ":" echo
root x 0 0 root /root /bin/bash
未进行-e解释转义字符;
[root@localhost ~]# echo "tony\ttony1\ttony2" | xargs -d "\t" echo
tony\ttony1\ttony2
进行-e解释转义字符;
[root@localhost ~]# echo  -e  "tony\ttony1\ttony2" | xargs -d "\t" echo
tony tony1 tony2
-p参数询问指令是否执行;-t参数直接执行
[root@localhost ~]# echo "yang ai lin" | xargs -p touch | ls
1  1.test  2  2.test  3  3.test  4  4.test
touch yang ai lin ?...y
[root@localhost ~]# ls .
1  1.test  2  2.test  3  3.test  4  4.test  ai  lin  yang
[root@localhost ~]# echo "yang@   ai@   lin@" | xargs -t touch | ls
1  1.test  2  2.test  3  3.test  4  4.test  ai  lin  yang
yang@ ai@ lin@    
​
-name 以...命名的文件; grep 过滤的是内容;
[root@localhost ~]# echo "yanghailin,dongchengdexiaoguniang,missyou" > 1.txt
[root@localhost ~]# echo "yanghailin,dongchengdexiaoguniang,missyou" > 2.txt
[root@localhost ~]# cat 1.txt ;cat 2.txt
yanghailin,dongchengdexiaoguniang,missyou
yanghailin,dongchengdexiaoguniang,missyou
[root@localhost ~]# find -name "*.txt" |xargs grep "missyou"
./1.txt:yanghailin,dongchengdexiaoguniang,missyou
./2.txt:yanghailin,dongchengdexiaoguniang,missyou
args默认只用一个进程执行命令。如果命令要执行多次,必须等上一次执行完,才能执行下一次。
--max-procs参数指定同时用多少个进程并行执行命令。--max-procs 2表示同时最多使用两个进程,--max-procs 0表示不限制进程数。$ docker ps -q | xargs -n 1 --max-procs 0 docker kill
上面命令表示,同时关闭尽可能多的 Docker 容器,这样运行速度会快很多
-n 次数 : 每次执行一次命令用多少个参数
echo {1..100..2} |xargs -n10  echo
1 3 5 7 9 11 13 15 17 19
21 23 25 27 29 31 33 35 37 39
41 43 45 47 49 51 53 55 57 59
61 63 65 67 69 71 73 75 77 79
81 83 85 87 89 91 93 95 97 99
​
Day5

1、alias
创建别名QF,使QF具有跟rm -rf一样的效果。

alias QF ="rm -rf"

2、history该命令可以显示最多个历史命令?

1000

3、mkdir 
    a、在/root内创建目录dir-1、dir-2 ....dir-100
    b、接下来在dir-1目录内创建A目录,在A目录内创建B目录(要求使用连级创建)

 mkdir -p dir-{1..100};mkdir -p /root/dir-1/A/B;

4、touch
    a、在/root/dir-1/A/B内创建文件file-1 到 file-10,这10个文件
    b、在file-1文件内使用echo追加重定向的方式写入内容“Hi Linux”

touch ./dir-1/A/B/file-{1..10} ;ls ./dir-1/A/B; echo "hi linux" >> ./dir-1/A/B/file-1 ; cat ./dir-1/A/B/file-1;

5、cp
    a、复制目录/root/dir-1到/opt
    b、复制目录/root/dir-100到/opt并改名为QF2208
    cp -p ./dir-1 /opt/dir-1;ls /opt ;mkdir -p /opt/dir-100;mv ./dir-100  opt/QF2208 ;ls/opt/QF2208 

6、mv
    a、将/opt下的dir-1目录改名为TEST
    b、移动/opt下的QF2208目录到/root

​   mv /opt/dir-1 /opt/Test ; ls /opt/Test; mv /opt/QF2208 /root/QF2208 ; ls ./QF2208 ;

7、rm
​    删除/root下所有以dir开头的文件e

rm -rf /root/dir-* ;ls .;

8、cat
    以显示行号的方式查看/opt/TEST/A/B/file-1

cat -n /opt/TEST/A/B/file-1

9、使用Linux中的vim文件编辑器完成下题

This is my summer vacation. I intend to finish the operation. 
Then, take a look at China's famous novel. 
Look at some day. 
Of course, also want to play with the computer, watch TV. 
Early every morning to get up and running to run, do other sports. 
But it is conducive to our body! 
But one thing should not be forgotten. 
must help parents do the housework! 
My holiday arrangements like? 
something good? 
give suggestions?


    

    1、将文章中的第五行内容复制并粘贴到最后一行下方。
        命令行模式5G【到第五行】yy【复制当前行】G【光标移到末行】p【粘贴到下方】
    2、删除第三行下方的所有内容。

    命令行模式4G【第三行保留,定位到第四行】dG【当前行到末尾删除】

    3、替换文章中所有的to为TO
    底线命令模式下:%s/to/TO/g
    
    4、将第一行内容另存到/opt下名为cp.txt
    底线命令模式下:1 w! /opt/cp.txt  【自动新建文件】
    cat /opt/cp.txt
    5、强制退出不保存
    底线命令模式下:q!
    6删除隐藏的.swp文件
    Linux vi 非正常退出都会在相应的位置保留.swp文件。并且这是隐藏文件,看不见
    每次再vi 的时候就会出现告警信息并且导致无法编辑。这个时候如果想要保存,那么先:revover--->编辑--->wq!-->删除对应的.swp文件(用rm -rf ./*.swp)。如果不想保存,那么直接删除.swp文件
    7.如果同名文件会内容覆盖;【逗号隔开代表着第二行到第四行】
    :2,4   w! /opt/cp.txt

Day6

()命令可以查看 XFS 文件系统信息。

  • Afdisk

  • Bxfs_info

  • Cxfs_repair

  • Ddf

正确答案:B

用户编写了一个文本文件 test.txt,若想将此文件名称修改为 a.txt,下列命令( )可以实

  • Acd test.txt a.txt

  • Bcat test.txt > a.txt

  • Crm test.txt a.txt

  • Decho test.txt > a.txt

正确答案:D

.

Linux 系统中文件系统的挂载配置文件是( )。

  • A/dev/sda

  • B/etc/profile

  • C/etc/passwd

  • D/etc/fstab

正确答案:D

当使用 mount 命令进行设备或文件系统挂载时,需要用到的设备名称位于( )位置。

  • A/dev

  • B/home

  • C/bin

  • D/etc

  • 正确答案A

假设用户所使用的系统上有两块 IDE 硬盘,查询第二块硬盘的分区情况的命令为( )。

  • Afdisk -l /dev/hda1

  • Bfdisk -l /dev/had

  • Cfdisk -l /dev/hdb

  • Dfdisk -l /dev/hdb2

  • 正确答案B

  • 系统服务及管理:查找文件

  • find:

  • which【whereis 】:查找命令所在位置

  • locate: updatedb; locate 文件名。查找文档的绝对路径 /tmp 临时文件找不到

find-路径-选项-表达式-动作【默认print 这个可以省略】

find命令详解
​
1. find命令作用
​
find命令用来在指定目录下查找文件。
​
2. find命令选项基本格式
find 目录 -选项 动作[-print -exec -ok …]
​
3. 常用选项:
​
-a:and 必须满足两个条件才显示
-o:or 只要满足一个条件就显示
-name:按照文件名查找文件
-iname:按照文件名查找文件(忽略大小写)
-type:根据文件类型进行搜索
-perm:按照文件权限来查找文件
-user 按照文件属主来查找文件。
-group 按照文件所属的组来查找文件。
-fprint 文件名:将匹配的文件输出到文件。
-newer file1 ! newer file2 查找更改时间比文件file1新但比文件file2旧的文件
​
4. 常用动作:
​
-print 默认动作,将匹配的文件输出到标准输出
-exec 对匹配的文件执行该参数所给出的命令。相应命令的形式为 'command' { } \;,注意{ }和\;之间的空格。
-ok 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。
-delete 将匹配到的文件删除
|xargs  将匹配到的文件删除   |xargs rm -rf 
​
a and 多个条件 -o or 其一即可  -name 按文件名 -iname 忽略大小写按文件名-type 按文件类型 -perm 按文件权限 -user 按文件属主 -group 按文件所属组 -fprint 按照匹配的文件;-newer f1!newer f2 更新时间比f1早比f2晚
[root@localhost ~]# #常用动作 -print 标准输出-exec 对匹配的文件执行该参数给出的命令-ok[较-exec更安 全]-delete查找匹配后删除 -xargus 扩展参数【执行命令在后面】
[root@localhost ~]# #忽略大小写查找以结尾的名字
[root@localhost ~]# find . -iname "to*.txt"
./tony.txt
./tony2.txt
[root@localhost ~]# #或
[root@localhost ~]# find . -iname  "*.txt" -o -iname "*.bash"
./tony.txt
./tony2.txt
[root@localhost ~]# #和
[root@localhost ~]# find . -name "t*" -a -name "*.txt"【查找以结尾和开头的】
./tony.txt
./tony2.txt
[root@localhost ~]# find . -name "t*.txt" 【和上述效果相同】
./tony.txt
./tony2.txt
​
[root@localhost ~]# find ./ -type f -name "*2.txt" -fprint ./tony.txt【查找结果输入到另一个文件中】
[root@localhost ~]# cat tony.txt
./tony2.txt
​
​
​
5根据文件类型进行搜索
​
-type 类型f 普通文件l 符号连接(软连接)d 目录b 块设备s 套接字
6. 基于目录深度搜索
1 向下最大深度限制为2
[root@localhost ~]# find /etc/  -maxdepth 2 -type d -atime -2 
/etc/
/etc/pki
/etc/pki/rpm-gpg
​
​
 搜索出深度距离当前目录至少7个子目录的所有文件
find /etc  -mindepth 7 -type f
​
7. 根据文件时间戳进行搜索
stat 
​
 UNIX/Linux文件系统每个文件都有三种时间戳:
access;modify[内容];change【权限大小 inode当改变字符时,文件大小不改变,存储字符的节点改变也会引起属性的改变。】
访问时间(-atime/天,-amin/分钟):用户最st近一次访问时间。
修改时间(-mtime/天,-mmin/分钟):文件最后一次修改时间
变化时间(-ctime/天,-cmin/分钟):文件数据元(例如权限等)最后一次修改时间。
 stat 命令查看:
[root@localhost ~]# stat /etc/passwd
  文件:"/etc/passwd"
  大小:1022            块:8          IO 块:4096   普通文件
设备:fd00h/64768d      Inode:16786823    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:system_u:object_r:passwd_file_t:s0
最近访问:2023-08-15 08:14:04.657151651 +0800
最近更改:2023-08-15 08:14:04.642151685 +0800
最近改动:2023-08-15 08:14:04.642151685 +0800
​
​
搜索最近2天内被访问过的所有文件【天数为负,几天内;天数为主,超过多少天】
​
[root@host-136 ~]# find /etc/ -type f -atime -3
[root@localhost ~]# find ./ -type f -atime -3
./.bash_profile
./.bashrc
./.bash_history
./tony.txt
./.tony.txt.swp
./tony2.txt
./.viminfo
​
 搜索超过七天内(7天外)被访问过的所有文件
​
[root@host-136 ~]# find /etc -type f -atime +7
​
8. 根据文件大小进行匹配
​
用法find . -type f -size 文件大小单元
[+大于;-小于 缺省时为符合当前大小]
文件大小单元:
b —— 块(512字节)c —— 字节w —— 字(2字节)
k —— 千字节M —— 兆字节G —— 吉字节 TB EB PB
​
[root@host-136 ~]# find /etc/ -type f -size +10k
[root@host-136 ~]# find /etc/ -type f -size -10k
[root@host-136 ~]# find /etc/ -type f -size 10k
 搜索大于1G的日志文件,并删除
[root@host-136 ~]# find /var/log -type f -name "*.log" -size +1G -delete
​
9. 根据文件权限/所有权进行匹配 【权限取反 在 -perm 之前】
找出指定目录下权限不是744的txt文件
[root@localhost ~]# find ./ -type f -name "*.txt"  ! -perm 744
./tony.txt
./tony2.txt
​
找出/home目录用户tony拥有的所有文件
​
[root@host-136 ~]# find /home/ -type f -user tony
找出/home目录用户组tony拥有的所有文件
​
[root@host-136 ~]# find /home/ -type f -group tony
​
10 借助-exec选项与其他命令结合使用
​
找出/tmp目录下所有root的文件,并把所有权更改为用户tony
​
find /tmp/ -type f -user root -exec chown frank {} \;
使用占位符{}来表示find到的文件名
​
找出家目录下所有的.sh文件并删除
​
[root@localhost home]# find $HOME -name "*.sh" -ok rm {} \;
find #HOME -name "*.sh" -exec rm {} \;
< rm ... /root/install_lnmp.sh > ? y
-ok和-exec行为一样,不过它会给出提示,是否执行相应的操作。
​
查找/home目录下所有.txt文件并把他们拼接到all.txt文件中
​
find /home/ -type f -name "*.txt" -exec cat {} \;>all.txt
1
查找/home目录下所有.txt文件并把他们复制到/opt/backup文件中
​
find /home/ -type f -name "*.txt" -exec cp {} /opt/backup/ \;
1
在/var/log目录中查找更改时间在5日以前的文件并删除它们:
​
find /var/log -type f -mtime +5 -exec rm {} \;
find /var/log -type f -mtime +5 |xargs rm -rf
​
​

1.将/etc/sysconfig/network-scripts/ifcfg-ens33 复制到/tmp下并且重新命名为ifcfg-ens33.bak

mv /etc/sysconfig/network-scripts/ifcfg-ens33 /tmp/ifcfg-ens33.bak; ls /tmp

2 在/etc/yum.repos.d/ 下创建 yumlist的文件夹。并且在此文件夹下创建 yum.repo文件

[root@localhost ~]# mkdir -p /etc/yumm.repos.d/yumlist

[root@localhost ~]# touch /etc/yumm.repos.d/yumlist/yum.repo

[root@localhost ~]# ls /etc/yumm.repos.d/yumlist

3 进入 yum.repo文件 编辑文件内容 hello world

[root@localhost ~]# echo "hello world" >> /etc/yumm.repos.d/yumlist/yum.repo

[root@localhost ~]# vim /etc/yumm.repos.d/yumlist/yum.repo

4 将 hello world 复制10行后保存文件。

命令模式下yy 10p w!

5 将hello全部替换为 welcome

底线命令模式下:%s/hello/welcome/g

6 快捷键删除第二行到页尾的文件内容,操作后不要保存,请直接退出

命令模式下2G dG 底线命令模式下: :q!

7 将yum.repo文件 移动到/tmp下

mv /etc/yumm.repos.d/yumlist/yum.repo /temp

8 在/tmp/yum.repo里显示行号

cat -n /tmp/yum.repo;

vim 模式下。底线命令模式下:set nu

9./etc/passwd 第二段是干什么的?以什么分割?

密码占位符【有无密码均可】 ,以冒号分割;

10.给服务器添加3个账号 xiaozhang xiaoli xiaowang

useradd xiaozhang ;useradd xiaoli ;useradd xiaowang;

grep 'xiao*' /etc/passwd

11.修改普通用户xiaowang 和root的密码

passwd xiaowang;

passwd;

12.创建用户jack和tom属于hr,wc组

第一种单个添加(追加);

groupadd hr; groupadd wc; useradd jack;useradd tom;

gpasswd -a tom hr; gpasswd -a tom wc;

gpasswd -a jack hr; gpasswd -a jack wc;

grep 'wc' /etc/group ; grep 'hr' /etc/gruop

第二种覆盖添加

userdel -r tom ;userdel -r jack; groupdel hr;group wc;

grep 'wc' /etc/group ; grep 'hr' /etc/gruop ;

gpasswd -M (原wc附加组成员,)jack,tom wc;gpasswd -M (原wc附加组成员,)jack,tom hr;

grep 'wc' /etc/group ; grep 'hr' /etc/gruop ;

第三种:直接添加到附属组

groupadd hr; groupadd wc; useradd jack -G hr,wc ;useradd tom -G wc,hr;

13.创建用户tony,属于hr,不属于wc组,并且将3个人的密码修改为 qianfeng

useradd tony ; gpasswd -a tony hrgrep 'hr' /etc/group

passwd tony; passwd jack; passwd tom;

14.将/etc/passwd前10行 内容写到 /tmp/passwd下。 然后将4-6行的 root换成haha

vim /etc/passwd命令模式下:1,10 w /tmp/passwd 底线命令模式 :q! 回车

vim /tmp/passwd命令模式下 : 4,6 s/root/haha/g

Day 7
du:显示文件大小和目录结构
描述:计算文件或目录的大小  
格式:~]# du   选项   文件或目录  
选项: 【-ash 功能和ls查看信息选项类似】 
-a  查看所有目录以及文件的容量信息  
-h  人性化显示容量信息  
-s  仅显示总容量
​
例:  
~]# du /root/       #显示/root/目录及其子目录的容量信息  
~]# du -a /root/        #显示/root/目录下所有目录和文件的容量信息(du默认不显示文件)  
~]# du -sh /root/   #显示/root/所占磁盘空间的总和
[root@localhost ~]# du .
0       ./a/b/c/1
0       ./a/b/c
0       ./a/b
0       ./a
0       ./webdata
284     .

​
ls -R 递归显示文件目录

.: 1.txt a ailin.txt dead.letter webdata

./a: b

./a/b: c

./a/b/c: 1

./a/b/c/1:

./webdata:

grep

描述:过滤文件中包含指定字符串的行(查找关键词并输出匹配的行) 格式:~]# grep [选项] 匹配模式 文件 选项: -i 忽略大小写 ingnore 【-v 取反匹配 】 【-w 匹配单词 】word -n 显示匹配结果所在的行号number --color 显示颜色

常用匹配模式: word 匹配字符串word ^word 以字符串word开头 word$ 以字符串word结尾

tar 制作压缩包(tar打包)

格式:tar 选项 /路径/压缩包名字 /源数据……

• tar 集成备份工具

– -c:创建归档

– -x:释放归档

– -f:指定归档文件名称,必须在所有选项的最后

– -z、-j、-J:调用 .gz、.bz2、.xz 格式工具进行处理

– -t:显示归档中的文件清单

– -C:指定释放路径

取反匹配 grep -v

[root@localhost ~]# grep -v root /etc/passwd |head -3 bin

❌1:1:bin:/bin:/sbin/nologin daemon

❌2:2:daemon:/sbin:/sbin/nologin adm

❌3:4:adm:/var/adm:/sbin/nologin

多个单词匹配;

shell quanxian /usr/bin/bash /sbin/nologin

1222 aabb

2222 aacc

3333 aaaadds

命令模式下:%s/1\|a/@/g 然后回车

shell qu@nxi@n /usr/bin/b@sh /sbin/nologin

@222 @@bb

2222 @@cc

3333 @@@@dd

转义符在命令行中加 -e;

转义符只有在有歧义时才进行转译

[root@localhost ~]# echo -e "hello\tworld;\n love you forever "

hello world;

love you forever

1.创建用户tom,jack,zhuzhuxia;zhuzhuxia用户的附加组为tom
useradd tom ;useradd jack ;useradd zhuzhuxia -G tom;

2.切换到用户tom,在/tmp目录下创建文件tom.txt (观察文件的归属和权限)
su - tom ;
touch /tmp/tom.txt;
su - ;输入密码1;ll /tmp/tom.txt; 
-rw-rw-r--. 1 tom tom 0 8月  16 16:03 /tmp/tom.txt 【此时文件的拥有者和附加组都是tom,664】

3.将tom创建的文件权限修改为rw-r-----
chmod 640 tom.txt
4.向tom创建的文件中写入内容"Tihs is tom file ,dont touch"
echo "Tihs is tom file ,dont touch" > /tmp/tom.txt
5.请问: jack,zhuzhuxia能不能查看文件的内容?
根据664,jack属于其他组,可以查看内容;zhuzhuxia属于附加组,也可以查看内容;
6.创建一个目录/opt/test目录,要求该目录的属组为it组,任何用户在该目录下创建文件继承该目录的属组?
mkdir -p /opt/test ;groupadd it; chown -R  .it /opt/test ;ll /opt/test

7.使用root用户创建目录/prov,修改属主为tom,属组为tom,权限为750
mkdir -p ./prov; chmod  750 ./prov ; chown tom.tom ./prov;
8.列出/home/下面的所有文件包括隐藏文件?
ll -a /home
9.查看自己的ip地址
ip a [ip addr]
10.chown是用来做什么的?chmod是用来做什么的?
chown 更改文件或用户 的主组和附属组;chmod更改读写执行权限;
11现有/home/A/ala.txt
1、alan.txt文件的UGO权限是777
2、A目录的拥有者是root,所属组是root,UGO权限是 700
3、home目录权限与初始化系统时的权限保持一致。


请问:用户alan是否可以在alan.txt文件内写入内容?
[root@localhost ~]# mkdir -p /home/A ; touch /home/A/ala.txt; chmod 777 /home/A/ala.txt;
[root@localhost ~]# chown root.root /home/A; chmod 700  /home/A; ll /home/A
总用量 0
-rwxrwxrwx. 1 root root 0 8月  16 17:54 ala.txt
[root@localhost ~]# su - tony 
[tony@localhost ~]$ echo "123" > /home/A/ala.txt
-bash: /home/A/ala.txt: 权限不够【要想子文件能执行,其父目录必须是可进入状态所以改为710,因为要切换用户能够执行,需要属组的人tony能够看到ala.txt所以应该为750】

Day8
 
1./路径 里面可执行的命令单行输出,可以做脚本。

不能直接目录或文件名,即使是当前家目录下。

[root@localhost ~]# vim file1

date
echo "hello2023"
read -p "请输入您的姓名: " name
echo "哈哈$name是大笨蛋;":
 

[root@localhost ~]# file1
-bash: file1: 未找到命令

[root@localhost ~]# ./file1
2023年 08月 19日 星期六 16:06:03 CST
hello2023
请输入您的姓名: 法外张三                      
哈哈法外张三是大笨蛋;:

2.权限提升;
2-1 命令行中u+s 所有人,visodo  给单个用户或用户组临时提权【查看,创建,修改删除权限要慎重】

[root@localhost ~]# ll  /usr/bin/cat
-rwxr-xr-x. 1 root root 54080 11月  6 2016 /usr/bin/cat
[root@localhost ~]# chmod u+s /usr/bin/cat ;ll /usr/bin/cat
-rwsr-xr-x. 1 root root 54080 11月  6 2016 /usr/bin/cat
[root@localhost ~]# echo 123 >11.txt ; su - alice;
上一次登录:六 8月 19 14:52:55 CST 2023pts/0 上
[alice@localhost ~]$ cat /root/11.txt
123
[root@localhost ~]# chmod u-s 1.txt
[root@localhost ~]# su - alice
上一次登录:六 8月 19 17:41:00 CST 2023pts/0 上
[alice@localhost ~]$ cat /root/1.txt  【只赋予Alice查看的权限】
123
[alice@localhost ~]$ rm -rf /root/1.txt
rm: 无法删除"/root/1.txt": 权限不够
 

【设置suid,使普通用户通过suid临时提权,查看超管root用户的文件】

root用户登录直接使用visudo命令进行编辑, visudo 命令实际修改的是 /etc/sudoers 文件

在里面给用户或用户组编辑【:set nu 显示行号编辑,在93行给某个成员临时提权】

 91 ## Allow root to run any commands anywhere
     92 root    ALL=(ALL)       ALL     
     93 alice   ALL=(ALL)       /usr/bin/cat
[,/usr/bin/touch]
 

 98 ## Allows people in group wheel to run all commands
     99 %wheel  ALL=(ALL)       ALL
    100                             【或者在100行处给某个组临时提权,】
[被管理主机的IP]、 [可以使用的身份]、 [授权的命令] 都可以使用 ALL 来表示不限制。
添加 [NOPASSWD: ] 选项可以使用户在使用sudo权限时不需要输入密码。

[授权的命令]要使用绝对路径,多条命令之间可用逗号( ,)分隔;
用户组 与 用户 的唯一区别是用户组前有个 %

2-2 目录g+s【继承附属组权限:用户在新建文件时,文件会自动继承目录的属组】

例如,创建共享目录/home/share;属组为shares;shares成员对目录具有读写执行权限,,其他用户没有任何权限【root除外】,在/home/share 中创建的文件会自动继承shares组;

useradd shares; mkdir /home/share;cd /home

chown .shares share;chmod 070 share; chmod g+s share;【在当前目录设置权限不用/】

-a, --add USER                向组 GROUP 中添加用户 USER【附属组+1】
  -d, --delete USER             从组 GROUP 中添加或删除用户
  -R, --restrict                向其成员限制访问组 GROUP
  -M, --members USER,...        设置组 GROUP 的成员列表【附属组+n,覆盖效果】
  -A, --administrators ADMIN,...    设置组的管理员列表
[root@localhost home]# gpasswd -M shares,alice,rose shares; grep 'shares' /etc/group
shares:x:2002:shares,alice,rose
 

2-3 目录o+t 【 sticky粘滞为:针对目录设置,目录内的文件,仅属主 能删除】

mkdir /home/sticky; chmod o+t  /home/sticky; 
 

2-4锁定/解锁文件【常用于锁定某个文件,拒绝修改。】
3让用户主组不显示用户名显示为uid[删除用户]

3.小知识点

3-1创建文件三种方法:touch,echo,vim

3-2切换用户后工作目录不变su 用户名

3-3命令间隔符: ||  &&

3-4修改用户密码的命令passwd ;    /usr/bin/passwd

3-5鼠标单击左键:选中功能

3-5vi编辑器有两种工作模式:命令模式和编辑模式【有,不是只有】V

     linux中系统中分为两类用户X.【三种管理员,系统用户,普通用户】

3-6创建用户实现的效果

useradd  jack; 【注意单词拼写passwd和命令行之间的空格】

1)在/etc/password,写入用户信息;

2)默认创建用户同名的组/etc/group

3)默认创建同名的家目录/home/jack

4) 默认创建同名的邮箱目录/var/spool/mail

[root@localhost ~]# useradd shares; grep 'shares' /etc/passwd; grep 'shares' /etc/group; ls -d /home/shares; ls -d /var/spool/mail/shares;

/home/shares
/var/spool/mail/shares
shares:x:2002:2002::/home/shares:/bin/bash
shares:x:2002:



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_45442261

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值