• LINUX初级 总结


    目录

     第一章

     1.3.3 cd  ls命令

    第二章 linux中执行命令

    2.1命令格式

    2.2 查看命令帮助

    2.3  date 命令

    2.4timedate命令

    2.5 ls命令

    第三章 Linux的文件类型和根目录结构

    文件类型:

     3.2linux的目录结构

    3.2.2 路径以及工作目录

    第四章 从命令行管理文件

    4.1创建链接文件

    4.2目录操作命令

    4.3普通文件的创建和删除

    4.4数据流和重定向

    4.5将标准输出重定向到文件

    4.6 tee命令读取数据输出到文件

    4.7 vim编辑器

    4.8 cp  mv

    第五章 文件内容显示

    第六章 文件的其他操作命令

    第七章 命令解释器 SHELL

    7.1 shell中的变量

    第八章 用户和组管理 

    8.1用户和组的分类

     8.2 用户管理

    8.3 用户组管理

    8.4查询用户和组信息

    8.5查看用户登录系统的情况

    第九章 Linux文件系统权限 

    9.2文件和目录的特殊权限

     第十章 管理linux的联网 

    10.1三种模式

    10.2配置网络

     10.3 从网站下载文件

    第十一章 管理LINUX软件包和进程

    管理工具:

    查看进程 

    信号控制进程

    十二章磁盘:存储设备

     第一章

     

     shell:命令解释器

    1. #解读
    2. [root@GBL ~]#
    3. root:登录用户 GBL:主机名称 ~:现在所在工作目录为登录用户的家目录 #:登录用户为超级用户root
    4. #查看主机名
    5. [root@GBL ~]# cat /etc/hostname
    6. GBL
    7. #获取IP
    8. 方法一
    9. [root@GBL ~]#dhclient
    10. 方法二:
    11. [root@GBL ~]# nmcli connection up 网卡名称
    12. #查看当前LINUX的发行版信息
    13. [root@GBL ~]# cat /etc/redhat-release
    14. Red Hat Enterprise Linux release 8.1 (Ootpa)
    15. #查看内核版本
    16. [root@GBL ~]# uname -r
    17. 4.18.0-147.el8.x86_64
    18. #查看当前登录用户
    19. [root@GBL ~]# whoami
    20. root
    21. [root@GBL ~]# who am i
    22. root pts/1 2022-08-22 08:22 (192.168.222.1)
    23. #临时修改主机名
    24. [root@GBL ~]# hostname 新名称
    25. #永久修改主机名
    26. [root@GBL ~]# hostnamectl set-hostname 新名称

     1.3.3 cd  ls命令

    1. #切换目录
    2. [root@GBL ~]# cd / -----工作目录切换到/目录
    3. [root@GBL /]# cd -----工作目录切换到~目录
    4. [root@GBL ~]# cd ~
    5. [root@GBL ~]#
    6. [root@GBL ~]# cd .. ------切换上一级
    7. [root@GBL /]#
    8. [root@GBL /]# cd . ------切换到当前(没啥用)
    9. [root@GBL /]#
    10. [root@GBL ~]# cd /
    11. [root@GBL /]# cd /test
    12. [root@GBL test]# cd - -----切换到之前的工作目录
    13. /
    14. #linux 中一切皆文件
    15. **ls**
    16. 1.不加后缀 查看当前目录
    17. 2.ls -l (ll) 列表形式显示信息
    18. 3.ls -a 显示隐藏文件
    19. 4.ls -hl 以长列表显示出来,以人类可读方式显示文件大小
    20. 5.ls -dl ~ 长格式查看目录本身信息
    21. 6.ls -R 查看本身有哪些内容,有颜色表示文件夹 .cfg表示配置文件
    22. 7.ls -i 显示文件索引节点,一个索引节点表示一个文件
    23. #ls 查看当前目录文件里有什么
    24. [root@GBL /]# ls
    25. bin dev home lib64 mnt proc run srv test usr
    26. boot etc lib media opt root sbin sys tmp var
    27. [root@GBL /]# cd dev
    28. [root@GBL dev]# cd /home -----同级切换,使用绝对路径
    29. [root@GBL /]# cd lib
    30. [root@GBL lib]# pwd
    31. /lib

    #重置root密码

    第二章 linux中执行命令

    2.1命令格式

    1. #命令后不跟操作对象,默认为当前
    2. [root@GBL ~]# pwd
    3. /root
    4. [root@GBL ~]# ls
    5. a Music
    6. a2 Pictures
    7. anaconda-ks.cfg Public
    8. Desktop sl-5.02-1.el8.x86_64.rpm
    9. Documents Templates
    10. Downloads test
    11. initial-setup-ks.cfg Videos
    12. [root@GBL ~]# ls /root
    13. a Music
    14. a2 Pictures
    15. anaconda-ks.cfg Public
    16. Desktop sl-5.02-1.el8.x86_64.rpm
    17. Documents Templates
    18. Downloads test
    19. initial-setup-ks.cfg Videos
    20. [root@GBL ~]#
    21. #命令分两类 ①内置builtin ②外部命令
    22. [root@GBL ~]# type cd
    23. cd is a shell builtin ----内置命令
    24. [root@GBL ~]# type man
    25. man is hashed (/usr/bin/man) ----man命令的可执行文件
    26. [root@GBL ~]# type cat
    27. cat is hashed (/usr/bin/cat) -----cat命令的可执行文件

    2.2 查看命令帮助

    • help  命令
    • 命令 --help
    • man  命令
    • info  page     

    2.3  date 命令

    1. [root@GBL ~]# date
    2. Sun Aug 21 20:49:01 CST 2022
    3. [root@GBL ~]# date -R
    4. Sun, 21 Aug 2022 20:58:30 +0800
    5. [root@GBL ~]# date -s "20201101 8:30:00"----空格分隔符后面一般跟下一个命令,这用“”
    6. Sun Nov 1 08:30:00 CST 2020
    7. [root@GBL ~]# date 110108302020
    8. Sun Nov 1 08:30:00 CST 2020
    9. [root@GBL ~]# date "+%j"
    10. 306
    11. [root@GBL ~]# date "+%Y-%m-%d %H:%M:%S"
    12. 2020-11-01 08:34:17

    2.4timedate命令

    2.5 ls命令

    1. [root@GBL ~]# ls ------ls命令一般查看目录下的文件
    2. a Documents
    3. a2 Downloads
    4. aa1 initial-setup-ks.cfg
    5. aa{1-3} Music
    6. aa2 Pictures
    7. aa3 Public
    8. anaconda-ks.cfg sl-5.02-1.el8.x86_64.rpm
    9. b Templates
    10. c test
    11. Desktop Videos
    12. [root@GBL ~]# ls -d ~ -----选项d表示查看目录本身内容
    13. /root
    14. [root@GBL ~]# ls -dl ~
    15. dr-xr-x---. 16 root root 4096 Aug 22 15:23 /root

    第三章 Linux的文件类型和根目录结构

    软链接与硬链接

     

    文件类型:

    d目录文件

    l 软链接文件 箭头指向链接到的文件

    _ 普通文件 类似Windows记事本 图片等

    c,b,p,s 字符设备 块设备 管道设备 套接字文件

     3.2linux的目录结构

    3.2.2 路径以及工作目录

    第四章 从命令行管理文件

    4.1创建链接文件

    1. [root@GBL ~]# mkdir /test
    2. [root@GBL ~]# cd /test
    3. [root@GBL test]# ll
    4. total 0
    5. [root@GBL test]# touch a
    6. [root@GBL test]# ll -i
    7. total 0
    8. 17395869 -rw-r--r--. 1 root root 0 Aug 22 21:14 a
    9. [root@GBL test]# ln a a.hard
    10. [root@GBL test]# ll -i
    11. total 0
    12. 17395869 -rw-r--r--. 2 root root 0 Aug 22 21:14 a
    13. 17395869 -rw-r--r--. 2 root root 0 Aug 22 21:14 a.hard
    14. [root@GBL test]# ln -s a a.soft
    15. [root@GBL test]# ll -i
    16. total 0
    17. 17395869 -rw-r--r--. 2 root root 0 Aug 22 21:14 a
    18. 17395869 -rw-r--r--. 2 root root 0 Aug 22 21:14 a.hard
    19. 17395870 lrwxrwxrwx. 1 root root 1 Aug 22 21:15 a.soft -> a
    20. [root@GBL test]#

    4.2目录操作命令

    1. #创建上下级目录 选项-p
    2. [root@GBL test]# cd /
    3. [root@GBL /]# mkdir -p /test/test2/test1
    4. #创建同级目录
    5. 1
    6. [root@GBL /]# mkdir /test/{hi,hihi,hih}
    7. [root@GBL /]# ll /test
    8. total 0
    9. -rw-r--r--. 2 root root 0 Aug 22 21:14 a
    10. -rw-r--r--. 2 root root 0 Aug 22 21:14 a.hard
    11. lrwxrwxrwx. 1 root root 1 Aug 22 21:15 a.soft -> a
    12. drwxr-xr-x. 2 root root 6 Aug 22 21:28 hi
    13. drwxr-xr-x. 2 root root 6 Aug 22 21:28 hih
    14. drwxr-xr-x. 2 root root 6 Aug 22 21:28 hihi
    15. drwxr-xr-x. 3 root root 19 Aug 22 21:22 test2
    16. 2
    17. [root@GBL /]# mkdir /test/test3 /test/test4
    18. [root@GBL /]# ll /test
    19. total 0
    20. -rw-r--r--. 2 root root 0 Aug 22 21:14 a
    21. -rw-r--r--. 2 root root 0 Aug 22 21:14 a.hard
    22. lrwxrwxrwx. 1 root root 1 Aug 22 21:15 a.soft -> a
    23. drwxr-xr-x. 2 root root 6 Aug 22 21:28 hi
    24. drwxr-xr-x. 2 root root 6 Aug 22 21:28 hih
    25. drwxr-xr-x. 2 root root 6 Aug 22 21:28 hihi
    26. drwxr-xr-x. 3 root root 19 Aug 22 21:22 test2
    27. drwxr-xr-x. 2 root root 6 Aug 22 21:32 test3
    28. drwxr-xr-x. 2 root root 6 Aug 22 21:32 test4

    4.3普通文件的创建和删除

    1. #创建普通文件
    2. [root@GBL /]# touch a b c
    3. [root@GBL /]# touch {1..3} #用法2:touch m{1..2}
    4. [root@GBL /]# touch {4,6}
    5. [root@GBL /]# ll
    6. total 30
    7. -rw-r--r--. 1 root root 0 Aug 22 21:34 1
    8. -rw-r--r--. 1 root root 0 Aug 22 21:34 2
    9. -rw-r--r--. 1 root root 0 Aug 22 21:34 3
    10. -rw-r--r--. 1 root root 0 Aug 22 21:35 4
    11. -rw-r--r--. 1 root root 0 Aug 22 21:35 6
    12. -rw-r--r--. 1 root root 0 Aug 22 21:34 a
    13. -rw-r--r--. 1 root root 0 Aug 22 21:34 b
    14. -rw-r--r--. 1 root root 0 Aug 22 21:34 c
    15. [root@GBL test]# touch {1,3}{a,b}
    16. [root@GBL test]# ls
    17. 1a 1b 3a 3b
    1. #删除普通文件
    2. /t1/t2/t3
    3. t2:a b c d e

    1. [root@GBL /]# mkdir -p /m1/m2/m3
    2. [root@GBL /]# mkdir m1/{a,b}
    3. [root@GBL /]# ls
    4. bin dev home lib64 media opt root sbin sys usr
    5. boot etc lib m1 mnt proc run srv tmp var
    6. [root@GBL /]# cd m1
    7. [root@GBL m1]# ls
    8. a b m2
    9. [root@GBL m1]# touch q w
    10. [root@GBL m1]# ls
    11. a b m2 q w
    12. [root@GBL m1]# rm -rf m2
    13. [root@GBL m1]# ls
    14. a b q w
    15. [root@GBL m1]# cd m2
    16. -bash: cd: m2: No such file or directory
    17. [root@GBL m1]#
    18. [root@GBL /]# rm -rf t1 ------选项rf可联用,rm可以用来删除目录
    19. #
    20. 删除前会询问:[root@GBL test]# rm 文件名
    21. 强制删除:[root@GBL test]# rm -f 文件名
    22. rm -rf可联用
    23. #
    24. 删除目录 rmdir 目录

     软链接和硬链接

    4.4数据流和重定向

    1. [root@GBL test]# date
    2. Tue Aug 23 09:19:54 CST 2022
    3. [root@GBL test]# ll
    4. total 0
    5. -rw-r--r--. 1 root root 0 Aug 23 08:53 1a
    6. -rw-r--r--. 1 root root 0 Aug 23 08:53 1b
    7. -rw-r--r--. 1 root root 0 Aug 23 08:53 3a
    8. -rw-r--r--. 1 root root 0 Aug 23 08:53 3b
    9. [root@GBL test]# date
    10. Tue Aug 23 09:20:14 CST 2022
    11. [root@GBL test]# date >> 1a
    12. [root@GBL test]# cat 1a
    13. Tue Aug 23 09:20:22 CST 2022
    14. [root@GBL test]# ls >> 1a
    15. [root@GBL test]# cat 1a
    16. Tue Aug 23 09:20:22 CST 2022
    17. 1a
    18. 1b
    19. 3a
    20. 3b
    21. [root@GBL test]# echo 123 > c
    22. [root@GBL test]# ls
    23. 1a 1b 3a 3b c
    24. [root@GBL test]# cat c
    25. 123
    26. [root@GBL test]#
    27. [root@GBL test]# ls /home /asasss > list.txt
    28. ls: cannot access '/asasss': No such file or directory
    29. [root@GBL test]# cat list.txt
    30. /home:
    31. redhat
    32. [root@GBL test]# ls /home /asasss > list.txt 2>list.txt
    33. [root@GBL test]# cat list.txt
    34. /home:
    35. redhat
    36. ess '/asasss': No such file or directory
    37. [root@GBL test]# cat > q
    38. q
    39. we
    40. sd
    41. ^C
    42. [root@GBL test]# ll
    43. total 16
    44. -rw-r--r--. 1 root root 41 Aug 23 09:20 1a
    45. -rw-r--r--. 1 root root 0 Aug 23 08:53 1b
    46. -rw-r--r--. 1 root root 0 Aug 23 08:53 3a
    47. -rw-r--r--. 1 root root 0 Aug 23 08:53 3b
    48. -rw-r--r--. 1 root root 4 Aug 23 09:21 c
    49. -rw-r--r--. 1 root root 55 Aug 23 09:33 list.txt
    50. -rw-r--r--. 1 root root 9 Aug 23 09:39 q
    51. [root@GBL test]# cat q
    52. q
    53. we
    54. sd
    55. [root@GBL test]#

    4.5将标准输出重定向到文件

    1. [root@GBL test]# echo $HOME
    2. /root
    3. [root@GBL test]# csa=1
    4. [root@GBL test]# echo $csa
    5. 1
    6. [root@GBL test]# echo test > file11
    7. [root@GBL test]# echo test2 >> file11
    8. [root@GBL test]# cat file11
    9. test
    10. test2
    11. [root@GBL test]#

    4.6 tee命令读取数据输出到文件

    1. [root@GBL test]# date | tee 1a -----date命令的输出,1a文件和屏幕上都有输出
    2. Tue Aug 23 10:02:11 CST 2022
    3. [root@GBL test]# cat 1a
    4. Tue Aug 23 10:02:11 CST 2022
    5. [root@GBL test]# date | tee -a 1a -----" -a "追加
    6. Tue Aug 23 10:03:33 CST 2022
    7. [root@GBL test]# cat 1a
    8. Tue Aug 23 10:02:11 CST 2022
    9. Tue Aug 23 10:03:33 CST 2022
    10. [root@GBL test]# date | tee x --------创建原目录下没有的文件
    11. Tue Aug 23 10:03:54 CST 2022
    12. [root@GBL test]# cat x
    13. Tue Aug 23 10:03:54 CST 2022
    14. [root@GBL test]#
    15. [root@GBL test]# echo 123 >> x1
    16. [root@GBL test]#
    17. [root@GBL test]# touch x2 < x1 ----这也可以创建文件x2,但x1的内容无法输入到x2
    18. [root@GBL test]# cat x2
    19. [root@GBL test]# cat x1
    20. 123
    21. [root@GBL test]#

    4.7 vim编辑器

    4.8 cp  mv

    1. [root@GBL test]# mkdir dir
    2. [root@GBL test]# touch a
    3. [root@GBL test]# cp a dir ------cp:复制
    4. [root@GBL test]# ll dir
    5. total 0
    6. -rw-r--r--. 1 root root 0 Aug 23 10:23 a
    7. [root@GBL test]# ls
    8. a dir
    9. [root@GBL test]# mv a dir ------mv:移动
    10. mv: overwrite 'dir/a'? y
    11. [root@GBL test]# ls dir
    12. a
    13. [root@GBL test]# ls
    14. dir
    15. [root@GBL test]# touch vb
    16. [root@GBL test]# ls
    17. dir vb
    18. [root@GBL test]# cp vb vb.1
    19. [root@GBL test]# ls
    20. dir vb vb.1
    21. [root@GBL test]# mv vb ./vb2
    22. [root@GBL test]# ls
    23. dir vb.1 vb2
    24. [root@GBL test]#

    第五章 文件内容显示

    5.1 浏览普通文件内容

    5.2 grep 过滤文件内容显示

    5.3 cut 切割显示

    5.4 sort 排序显示

    5.5 uniq 去重显示

    5.6 tr  替换文件中的字符显示

    1. #查看文件内容
    2. cat---查看文件内容
    3. tac---倒序查看文件内容
    4. more 和 less 区别: more自动退出 less按q手动退出
    5. more -行号 文件名------- 指定一次有几行去翻页,less和cat无此用法
    6. #只看开头/结尾 的几行
    7. head 文件名 ------默认查看开头前10行
    8. head/tail -行号 文件名 ------ 查看前几行/后几行
    9. head -7 文件名 | tail -1-------只查看某一文件的第七行
    10. tail 文件名------查看结尾后10行
    11. tail -f 文件名-----不停读取和显示文件最新内容
    12. #grep 过滤文件内容显示
    13. 命令格式:grep 选项 关键字符串 文件名称
    14. grep -n xxx 文件名-----显示行号
    15. grep ^xxx 文件名-----显示以xxx开始的行
    16. grep xxx$ 文件名-----显示以xxx结尾的行
    17. #空行 显示文件中空行 并标记行号 ?
    18. grep r.*t 文件名---过滤以r开头d结尾
    19. grep 'r . . t' 文件名 -----只过滤四个字母
    20. grep r . . t 文件名---过滤四个字母
    21. grep [123] 文件名----匹配[]里面任意一个
    22. grep ^[^qf] 文件名----不匹配以q/f开头的行
    23. #切割显示
    24. 选项:-d间隔符号 -f设置需要看的列数 -c
    25. 用法
    26. 1. cut -d : -f 列数 文件名
    27. 2. cut -d : -f 1,2 文件名-----选不同多列,用逗号隔开
    28. 3. cut -d : -f 1-4 文件名----- 选1-4连续的几列
    29. #排序显示SORT
    30. sort 文件名------按每行首字符大小排序---先排符号,数字,字母
    31. sort -n 文件名------按数字大小排序
    32. sort -u 文件名-----排序后去重(消除文件中重复内容,保留一个)
    33. #去重显示uniq
    34. uniq 文件名------消除连续行重复内容,保留1个
    1. #替换文件中的字符 tr
    2. *tr 将原来内容替换新的内容 再输出
    3. [root@GBL test]# cat a
    4. hi
    5. hello
    6. my name
    7. is GBL
    8. my phone
    9. 1092839
    10. as
    11. 1324
    12. [root@GBL test]# cat a | tr as 1 -------文件a中的a和s都替换为1
    13. hi
    14. hello
    15. my n1me
    16. i1 GBL
    17. my phone
    18. 1092839
    19. 11
    20. 1324
    21. [root@GBL test]# cat a | tr hi o ------文件a中的h和i都替换为o
    22. oo
    23. oello
    24. my name
    25. os GBL
    26. my poone
    27. 1092839
    28. as
    29. 1324
    30. [root@GBL test]# cat a | tr "is GBL" " " -----文件a中的 "is GBL" 替换为空(相当于把内容删除)
    31. h
    32. hello
    33. my name
    34. my phone
    35. 1092839
    36. a
    37. 1324

    第六章 文件的其他操作命令

    6.1 wc 文本内容统计

    1. [root@GBL test]# wc -l a -------行数
    2. 8 a
    3. [root@GBL test]# wc -w a -------单词数
    4. 11 a
    5. [root@GBL test]# wc -c a -------字节数
    6. 51 a
    7. [root@GBL test]# cat -n a
    8. 1 hi
    9. 2 hello
    10. 3 my name
    11. 4 is GBL
    12. 5 my phone
    13. 6 1092839
    14. 7 as
    15. 8 1324

    6.2 cp mv 复制移动文件

    -a  等同于-d -p -r 

    1. #方法一
    2. [root@GBL test]# cat /etc/passwd | cut -d : -f 1 | sort -r
    3. [root@GBL test]# cut -d : -f 1 passwd | sort -r
    4. #方法二
    5. [root@GBL test]# hostname -I
    6. 192.168.222.128 192.168.122.1

    6.3 查找文件路径

    1. [root@GBL ~]# whereis ls
    2. ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
    3. [root@GBL ~]# /usr/bin/ls
    4. anaconda-ks.cfg Pictures
    5. Desktop Public
    6. Documents sl-5.02-1.el8.x86_64.rpm
    7. Downloads Templates
    8. initial-setup-ks.cfg Videos
    9. Music
    10. [root@GBL ~]# which ls
    11. alias ls='ls --color=auto'
    12. /usr/bin/ls
    13. [root@GBL ~]# find /test -name a
    14. /test/dir/a
    15. /test/a
    16. [root@GBL ~]# find /etc -name "host*"
    17. /etc/host.conf
    18. /etc/hosts
    19. /etc/hostname
    20. /etc/avahi/hosts
    21. [root@GBL ~]# find . -name "a*"
    22. ./anaconda-ks.cfg
    23. ./.cache/evolution/addressbook
    24. ./.local/share/gnome-shell/application_state
    25. ./.local/share/evolution/addressbook
    26. ./.local/share/applications
    27. [root@GBL ~]# cd /test
    28. [root@GBL test]# find . -name "a*"
    29. ./dir/a
    30. ./a
    31. [root@GBL test]# find ./* -name '*a'
    32. ./a
    33. ./dir/a
    34. [root@GBL test]#
    35. [root@GBL test]# find ./* -name '*.txt' -exec cp {} ./cp.txt \;
    36. #find 不和 管道符联用
    37. [root@GBL test]# find ./* -name '*.txt' | cp ./cp.txt
    38. cp: missing destination file operand after './cp.txt'
    39. Try 'cp --help' for more information.

    6.4 压缩和解压缩

     6.5 tar 归档命令

    1. [root@GBL test]# tar cvf passwd.tar passwd
    2. passwd
    3. [root@GBL test]# ls
    4. a dir passwd passwd.tar vb.1 vb2
    5. [root@GBL test]# tar tf passwd.tar
    6. passwd
    7. [root@GBL test]# touch e r t
    8. [root@GBL test]# tar rvf passwd.tar e
    9. e
    10. [root@GBL test]# tar tf passwd.tar
    11. passwd
    12. e
    13. [root@GBL test]# tar czf passwd.tar.gz passwd
    14. [root@GBL test]# ls
    15. a e passwd.tar r vb.1
    16. dir passwd passwd.tar.gz t vb2
    17. [root@GBL test]# tar rvf passwd.tar.gz e
    18. tar: Cannot update compressed archives
    19. tar: Error is not recoverable: exiting now
    20. [root@GBL test]#
    21. [root@GBL test]# tar xvf passwd.tar.gz -C ./dir
    22. passwd
    23. [root@GBL test]# ll dir
    24. total 0
    25. -rw-r--r--. 1 root root 0 Aug 23 10:23 a
    26. drwxr-xr-x. 2 root root 6 Aug 23 21:19 c
    27. drwxr-xr-x. 2 root root 6 Aug 23 21:19 d
    28. -rw-r--r--. 1 root root 0 Aug 23 21:21 m1
    29. -rw-r--r--. 1 root root 0 Aug 23 21:21 m2
    30. -rw-r--r--. 1 root root 0 Aug 23 21:31 passwd
    31. [root@GBL test]#

    第七章 命令解释器 SHELL

    7.1 shell中的变量

    • 普通变量(局部变量)
    • 环境变量(全局变量)
      1. #普通变量的赋值
      2. [root@GBL ~]# name=123
      3. [root@GBL ~]# echo $name
      4. 123
      5. [root@GBL ~]# name='123'
      6. [root@GBL ~]# echo $name
      7. 123
      8. [root@GBL ~]# name="123"
      9. [root@GBL ~]# echo $name
      10. 123
      11. [root@GBL ~]#
      12. [root@GBL ~]# name=`pwd`
      13. [root@GBL ~]# echo $name
      14. /root
      15. [root@GBL ~]# name=$(pwd)
      16. [root@GBL ~]# echo $name
      17. /root
      18. [root@GBL ~]#
      19. [root@GBL test]# vim var.sh
      20. [root@GBL test]# chmod +x var.sh
      21. [root@GBL test]# ./var.sh
      22. 1

     

     

     环境变量

    7.2命令历史 history

    7.3命令别名 alias 

    1.命令格式:alias 别名=’ 原命令‘

    2.linux中提供alias永久化的方法

    1. #暂时性修改
    2. [root@GBL /]# alias cdt='cd /test'
    3. [root@GBL /]# cdt
    4. [root@GBL test]# su redhat
    5. [redhat@GBL test]$ cdt
    6. bash: cdt: command not found...
    7. Failed to search for file: Cannot update read-only repo
    8. #永久性修改(修改配置文件)
    9. [root@GBL ~]# cdt
    10. [root@GBL test]# su redhat
    11. [redhat@GBL test]$ cdt
    12. [redhat@GBL test]$

    7.4 linux中的特殊符号

    1. #符号 ;使用分号分隔多条命令
    2. [root@GBL ~]# pwd ;cat /test/a
    3. /root
    4. hi
    5. hello
    6. my name
    7. is GBL
    8. my phone
    9. 1092839
    10. as
    11. 1324
    12. #符号 \ 使\后面的特殊字符失效,换行后系统自动显示提示符>
    13. [root@GBL ~]# cat a \
    14. >
    15. #
    16. ?:匹配任意单个字符
    17. ` :反引号一般用于引用命令
    18. '':单引号里所有特殊字符失去含义
    19. " " :双引号里部分特殊字符保留原有含义

     7.5linux中的快捷键

    ctrl+a光标移动到当前行开头
    ctrl+e光标移动到当前行结尾
    ctrl+u删除光标前的内容 ,光标所在内容不会删除
    ctrl+k删除光标后的内容,光标所在内容也会删除

    第八章 用户和组管理 

    8.1用户和组的分类

    1.linux下的用户分为三类:超级用户root 系统用户 普通用户

       linux下的组:基本组,附加组

    2.用户和组的配置文件

    用户账号文件/etc/passwd,该文件中,系统用户uid 1-999 普通用户uid >=1000 超级用户uid 0,/bin/bash 和 /sbin/nologin 是否可登录
    用户密码文件/etc/shadow
    组账号文件/etc/group
    组密码文件/etc/gshadow

     

     8.2 用户管理

    1. #1.添加新用户
    2. #选项 -g:为用户指定基本组 -G指定附加组 -s设置可登录
    3. [root@GBL ~]# useradd test1
    4. [root@GBL ~]# tail -1 /etc/shadow
    5. test1:!!:19229:0:99999:7::: ------感叹号表示未给test1用户设置密码
    6. [root@GBL ~]# passwd test1 --------设置密码123
    7. New password:
    8. Retype new password:
    9. [root@GBL ~]# tail -1 /etc/shadow
    10. test1:$6$PGsAXhnDv7Gf8Bwu$Ype3.3AIcxxbfCl9l3Dpr93D4Ajb9mxDjmAQEHZbGdJKjTlfMEtP6o.G7BW0NRtJTYq7KXKbAYe8K.7LNnm2k0:19229:0:99999:7:::
    11. [root@GBL ~]# useradd test2 -p 123 ------在创建test2用户时去设置密码,注意:-p后跟加密的密码
    12. [root@GBL ~]# tail -1 /etc/shadow
    13. test2:123:19229:0:99999:7:::
    14. #2.修改用户信息
    15. 命令格式: usermod [选项] username
    16. 选项: -i 新用户名 :更改账户名称,必须在用户未登录情况下才用
    17. #3.为用户账号设置密码
    18. 方式1:passwd
    19. 修改密码:方式2:echo 密码 | passwd --stdin 用户名
    20. #4.删除用户账号 userdel
    21. userdel [-r] 账号名 -----r选项,删除该账号时,一并删除账号对应主目录,此时主目录对应的所属者和所属组会发生变化
    22. [root@GBL ~]# ll /home
    23. total 4
    24. drwx------. 15 redhat redhat 4096 Aug 24 16:36 redhat
    25. drwx------. 3 test1 test1 78 Aug 25 08:21 test1
    26. drwx------. 3 test2 test2 78 Aug 25 08:34 test2
    27. [root@GBL ~]# userdel test1 -----删除账号,账号对应主目录保留
    28. [root@GBL ~]# ll /home
    29. total 4
    30. drwx------. 15 redhat redhat 4096 Aug 24 16:36 redhat
    31. drwx------. 3 1001 1001 78 Aug 25 08:21 test1
    32. drwx------. 3 test2 test2 78 Aug 25 08:34 test2
    33. [root@GBL ~]# userdel -r test2 ----账号和主目录一并删除
    34. #5.用户间切换 su命令
    35. su 和 su - 命令的区别在于加载的配置文件不同
    36. #6.控制用户对系统命令的使用权限 sudo
    37. [root@GBL ~]# su redhat
    38. [redhat@GBL root]$ cat /etc/shadow
    39. cat: /etc/shadow: Permission denied
    40. [redhat@GBL root]$ sudo cat /etc/shadow
    41. We trust you have received the usual lecture from the local System
    42. Administrator. It usually boils down to these three things:
    43. #1) Respect the privacy of others.
    44. #2) Think before you type.
    45. #3) With great power comes great responsibility.
    46. [sudo] password for redhat:
    47. root:$6$EOcEges3dkzDaRrz$nurkYwv.YYHr8YdNp8CRiRuyLAX7hT1tDs28WWoD2Q0cNsb22QGODwRGfrC1a9lEG3L3WeBiu.b5ssTX4Cdyx1:19227:0:99999:7:::
    48. tcpdump:!!:19219::::::
    49. redhat:$6$TbqE2nL1ki3qo4er$adoKII34NF4reMyOvWlrYlgxeRWDZTx2w5UQ8ImCuq2.NtsIgYtVqwxoukgJbhPW.m4BZCM6f4PpZIM.tRLHh.::0:99999:7:::
    50. apache:!!:19225::::::
    51. test2:123:19229:0:99999:7:::
    52. [redhat@GBL root]$ cat /etc/shadow
    53. cat: /etc/shadow: Permission denied
    54. [redhat@GBL root]$

     详细说sudo

    sudo命令:提高普通用户的操作权限,这个权限需要root用户进行配置/etc/sudoers文件才可使用。配置/etc/sudoers文件的两种方式:1.vim /etc/sudoers  2.visudo

    8.3 用户组管理

    1.创建用户组

    命令格式:groupadd [-r]  用户组名称

    2.修改用户组属性

    groupmod 选项 用户组

    3.添加/删除组成员(只有root用户和组管理员才可使用该命令)

    gpasswd  [选项]  [用户]  [组]

    4.删除组账号

    groupdel 用户组名

     注意:删除一个基本组,1.用户和其基本组一起删除 2给用户换个基本组,原先基本组中没有任何用户

    8.4查询用户和组信息

    显示某个用户的详细信息 :id 用户名

    显示用户的所属组信息:groups 用户名

    8.5查看用户登录系统的情况

    1.查看当前登录系统的用户 users

     此处三个登录用户root,有一个是虚拟机上登陆的root用户,其余两个都是在xshell上登陆的root用户。

    2.列出目前与过去登入系统的用户相关信息 last,此命令默认读取/var/log/wtmp文件

    tty : VM上的终端

    pts:虚拟终端,XSHELL上的终端

    3.查看每个账号的最近登陆时间,lastlog,该命令会读取/var/log/lastlog文件

     4.显示登录到系统的用户信息 w

     5.显示目前登录到系统的用户 who,who 通常通过/var/run/utmp文件来获取信息

    1. [root@GBL ~]# whoami #当前所登陆的用户
    2. root
    3. [root@GBL ~]# who am i
    4. root pts/1 2022-08-25 08:15 (192.168.222.1)
    5. [root@GBL ~]#
    6. [root@GBL ~]# su redhat
    7. [redhat@GBL root]$ whoami #当前所登陆的用户
    8. redhat
    9. [redhat@GBL root]$ who am i #会话登录的用户
    10. root pts/1 2022-08-25 08:15 (192.168.222.1)
    11. [redhat@GBL root]$

    第九章 Linux文件系统权限 

     root账号不受文件权限的r,w权限限制,x权限受限制

    1.修改文件权限方法

    文件原权限更改后的权限方法
    cr-x r-x r-xr-x rwx rwx

    1.g,o+w

    2.g=rwx,o=rwx

    arwx r-x r-xrwx r-- ---

    1.g-x,o-r,x

    2.g=r--,o=-

    br-x r-x r-xrwx rwx rwx

    1.777

    2.a+w

    3.a=rwx

    1. [root@GBL ~]# touch a
    2. [root@GBL ~]# ls a
    3. a
    4. [root@GBL ~]# ll a
    5. -rw-r--r--. 1 root root 0 Aug 25 14:00 a
    6. [root@GBL ~]# chmod g-r,o-r a
    7. [root@GBL ~]# ll a
    8. -rw-------. 1 root root 0 Aug 25 14:00 a
    9. [root@GBL ~]# chmod u=r--,o=r-- a
    10. [root@GBL ~]# ll a
    11. -r-----r--. 1 root root 0 Aug 25 14:00 a
    12. [root@GBL ~]# touch b
    13. [root@GBL ~]# ll b
    14. -rw-r--r--. 1 root root 0 Aug 25 14:02 b
    15. [root@GBL ~]# chmod g=r+w,o=- b
    16. [root@GBL ~]# ll b
    17. -rw-rw----. 1 root root 0 Aug 25 14:02 b

    1. #修改文件a的所属者和所属组,前提是更换的所属者和所属组都存在
    2. [root@localhost ~]# ll a
    3. -rw-r--r--. 1 root root 0 Sep 6 10:42 a
    4. [root@localhost ~]# chown redhat:redhat a-----同时更换所属者和所属组
    5. [root@localhost ~]# ll a
    6. -rw-r--r--. 1 redhat redhat 0 Sep 6 10:42 a
    7. [root@localhost ~]#
    8. [root@localhost ~]# chown :root a----更换所属组
    9. [root@localhost ~]# ll a
    10. -rw-r--r--. 1 redhat root 0 Sep 6 10:42 a
    11. [root@localhost ~]# chown root a----更换所属者
    12. [root@localhost ~]# ll a
    13. -rw-r--r--. 1 root root 0 Sep 6 10:42 a
    14. [root@localhost ~]#
    15. [root@localhost ~]# chown :xixi a -----更换的所属组名称不存在时,无法更换
    16. chown: invalid group: ‘:xixi
    17. [root@localhost ~]# chown hah a
    18. chown: invalid user: ‘hah
    19. [root@localhost ~]#

    对于文件和目录来说,r w x有着不同的含义

     文件:--x可以用,尽量不用

    目录:r--是不可能出现的,必须是r-x

    9.2文件和目录的特殊权限

    查找命令的可执行文件

    whereis  which   locate   find

    1.SUID权限,让一般用户在执行某些程序的时候,在程序运行期间,暂时获得该程序文件所属者权限。u+s

    1. [root@localhost ~]# which passwd
    2. /usr/bin/passwd
    3. [root@localhost ~]# passwd
    4. Changing password for user root.
    5. New password:
    6. [root@localhost ~]# su redhat
    7. [redhat@localhost root]$ passwd
    8. Current password:
    9. New password:
    10. [root@localhost ~]# ll /usr/bin/passwd
    11. -rwsr-xr-x. 1 root root 33544 Dec 14 2019 /usr/bin/passwd
    12. [root@localhost ~]# ll /etc/shadow
    13. ----------. 1 root root 1346 Sep 6 14:26 /etc/shadow
    14. [root@localhost ~]#

     2.SGID权限(g+s)

    SGID是设置在A目录上,则A目录内建立的文件或目录的属组,将会是此A目录的所属组。

    3.ACL权限,给指定的用户指定目录分配指定的权限

    查看ACL权限 : getfacle 文件名

    设定ACL权限:setfacl 选项 文件名

    4.Sticky Bit 权限,当前只针对目录有效,对文件没有效果。(o+t)

     5.权限掩码

     第十章 管理linux的联网 

    10.1三种模式

    桥接模式和NAT模式都可以连外网

    仅主机模式:只能和主机相连

    仅主机模式图示

     NAT模式图示

    桥接模式图示

    10.2配置网络

    网络接口这里是指计算机的网络接口即网卡设备,一个网络接口,可以有多个网络连接,但同一时间只能有一个网络连接处于活动状态。会话和网卡的关系:一个网卡可以有多个会话,但一个时刻只能连接到一个会话。

    1.使用ip命令配置临时生效的网络连接

     2.修改配置文件,前提需要有network服务

     3.nmcli命令行工具

    1. 查看网卡设备
    2. nmcli device 简写 nmcli d
    3. nmcli device show
    4. 查看相应会话
    5. nmcli connection 简写 nmcli c
    6. nmcli connection show
    7. 配置已存在会话的网卡的IP地址
    8. #非交互式
    9. nmcli c mo ens160 ipv4.method manual ipv4.addresses 192.168.150.200/24 ipv4.gateway 192.168.150.2 ipv4.dns 223.5.5.5 autoconnect yes
    10. 连接,断开,删除会话
    11. nmcli c up ethx
    12. nmcli c down ethx
    13. nmcli c delete ethx

     10.3 从网站下载文件

    1.wget命令用于在终端命令行下载网络文件,语法:wget [选项]  网址

    2.curl命令是一个网络工具,作用:通过http,https,ftp等方式下载或上传文件

    第十一章 管理LINUX软件包和进程

    管理工具:

    rpm 和 yum/dnf

    1. [root@localhost ~]# rpm -qf /usr/bin/tree
    2. tree-1.7.0-15.el8.x86_64
    3. [root@localhost ~]# rpm -qi tree
    4. Name : tree
    5. Version : 1.7.0
    6. Release : 15.el8
    7. Architecture: x86_64
    8. Install Date: Sun 28 Aug 2022 08:11:12 PM CST
    9. Group : Unspecified
    10. Size : 111611
    11. License : GPLv2+
    12. Signature : RSA/SHA256, Thu 08 Nov 2018 01:20:51 AM CST, Key ID 199e2f91fd431d51
    13. Source RPM : tree-1.7.0-15.el8.src.rpm
    14. Build Date : Thu 08 Nov 2018 12:49:35 AM CST
    15. Build Host : x86-vm-10.build.eng.bos.redhat.com
    16. Relocations : (not relocatable)
    17. Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
    18. Vendor : Red Hat, Inc.
    19. URL : http://mama.indstate.edu/users/ice/tree/
    20. Summary : File system tree viewer
    21. Description :
    22. The tree utility recursively displays the contents of directories in a
    23. tree-like format. Tree is basically a UNIX port of the DOS tree
    24. utility.
    25. [root@localhost ~]# rpm -ql tree
    26. /usr/bin/tree
    27. /usr/lib/.build-id
    28. /usr/lib/.build-id/50
    29. /usr/lib/.build-id/50/ae300877a586b9e7b87f19dfe58d303a887fb9
    30. /usr/share/doc/tree
    31. /usr/share/doc/tree/LICENSE
    32. /usr/share/doc/tree/README
    33. /usr/share/man/man1/tree.1.gz
    34. [root@localhost ~]# rpm -qa tree
    35. tree-1.7.0-15.el8.x86_64
    36. [root@localhost ~]# which httpd
    37. /usr/sbin/httpd
    38. [root@localhost ~]# rpm -qf /usr/sbin/httpd
    39. httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64
    40. [root@localhost ~]# rpm -ql httpd
    41. /etc/httpd/conf
    42. /etc/httpd/conf.d/autoindex.conf
    43. /etc/httpd/conf.d/userdir.conf
    44. /etc/httpd/conf.d/welcome.conf
    45. ......
    46. ....
    47. ...
    48. [root@localhost ~]# rpm -qa httpd
    49. httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64
    50. [root@localhost ~]#
    51. [root@localhost ~]# rpm -qi httpd
    52. Name : httpd
    53. Version : 2.4.37
    54. Release : 41.module+el8.5.0+11772+c8e0c271
    55. Architecture: x86_64
    56. Install Date: Fri 02 Sep 2022 11:56:11 AM CST
    57. Group : System Environment/Daemons
    58. Size : 4494146
    59. License : ASL 2.0
    60. Signature : RSA/SHA256, Sat 17 Jul 2021 04:10:19 PM CST, Key ID 199e2f91fd431d51
    61. Source RPM : httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.src.rpm
    62. Build Date : Tue 13 Jul 2021 05:40:41 AM CST
    63. Build Host : x86-vm-07.build.eng.bos.redhat.com
    64. Relocations : (not relocatable)
    65. Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
    66. Vendor : Red Hat, Inc.
    67. URL : https://httpd.apache.org/
    68. Summary : Apache HTTP Server
    69. Description :
    70. The Apache HTTP Server is a powerful, efficient, and extensible
    71. web server.
    72. [root@localhost ~]#

    查看进程 

    静态查看进程:ps

            pstree(进程树)

    动态查看进程:top 

    信号控制进程

    1. kill -9 pid(进程号)
    2. killall vim
    3. killall httpd

    十二章磁盘:存储设备

    拿到一个磁盘,要做如下三步骤:

    1.分区

        管理,划分分区三工具:

    • fdisk:默认化为MBR格式的分区, MBR分区:4个主分区或3主分区带1扩展分区(在扩展分区里划分逻辑分区) 一个分区最大2.2TB
    • gdisk:默认将磁盘化为GPT格式的分区,  GPT格式:默认情况下,支持128个分区
    • parted

     2.对每块分区进行格式化

    格式化:在存储设备上组织文件方法

    1. #命令
    2. mkfs.格式 分区的设备名
    3. #格式
    4. 格式有:xfs ext2(无日志) ext3(有日志) ext4

    3.挂载

    什么是挂载?挂载就是将分区或设备挂载至挂载点目录,挂载后可以对磁盘上的文件进行正常的读写

    1. #挂载命令
    2. mount 设备名 挂载点目录
    3. mount -u uuid 挂载点目录
    4. #查看挂载信息
    5. mount | grep /dev/sda
    6. #卸载分区
    7. umount 挂载点目录/存储设备名
    8. #永久挂载
    9. 在/etc/fstab 配置文件下更改

     

     管理交换分区

    什么是交换分区?swap交换分区,类似于windows系统中的“虚拟内存”

    查看磁盘空间使用量 df du

    df:列出磁盘空间的占用情况

            df  [参数]  [目录或文件名]

    du:显示磁盘空间的使用量

            du  [参数]   目录或文件名

    磁盘最小存储单元:扇区

    操作系统对磁盘最小读取单位:簇/块,多扇区组成簇或块

    查看磁盘信息:lsblk

    查看格式化后的磁盘分区信息:blkid

  • 相关阅读:
    java毕业设计教师教学质量评价管理Mybatis+系统+数据库+调试部署
    Redis-使用java代码操作Redis
    mysql8.0.31 源码阅读
    28_content 阶段的 index 模块
    C语言必会15个文件函数
    Android之启动奔溃提示异常java.lang.SecurityException: Permission Denial: startForeground
    操作系统——复习笔记
    Unity学习资源(超全)汇总 基础+项目+进阶+面试
    经纬恒润 标记重复元素 python
    安美数字酒店宽带运营系统 server_ping.php 远程命令执行漏洞
  • 原文地址:https://blog.csdn.net/weixin_55739782/article/details/126454897