Linux1024一篇通俗易懂的liunx命令操作总结(第十课)
一 liunx 介绍
Linux是一种免费开源的操作系统,它的设计基于Unix。它最早是由芬兰的一位大学生Linus Torvalds在1991年开始编写的,取名为Linux。Linux具有高度的灵活性和可定制性,可以在不同的硬件平台上运行,并支持多个用户同时使用。Linux系统是GNU计划的一部分,GNU是一个旨在开发自由软件的计划。
Linux分为内核和发行版。内核是操作系统的核心部分,它控制着计算机硬件和资源的管理。发行版则是由内核和其他软件组成的完整操作系统。常见的Linux发行版有Ubuntu、Debian、Fedora、CentOS、Red Hat等。
Linux的特点包括:
-
开源:Linux的源代码可以免费获取,用户可以根据自己的需要自由修改和分发。
-
多用户:Linux支持多个用户同时使用,每个用户都可以有自己的个人账户和权限。
-
高度定制化:Linux可以根据用户的需求进行高度的定制,用户可以选择自己需要的桌面环境、软件等。
-
安全性高:由于Linux的源代码公开,使得许多开发人员对其进行审查,也使Linux系统更加安全,而且不容易受到病毒攻击。
-
良好的兼容性:Linux可以运行在不同的硬件平台上,并且支持许多不同的文件格式和协议。
-
可靠性高:Linux系统的稳定性和可靠性非常高,可以长时间运行而不会出现问题。
总之,Linux是一种非常强大和可定制的操作系统,它的开源和多样性吸引了很多程序员和用户使用和开发。
1 认识Linux操作系统的结构目录




2 ls less cat 查询命令
Haskell
[root@localhost ~]# ls
anaconda-ks.cfg bin tuxwhitebg.jpg usr
[root@localhost ~]# ls /
afs boot etc lib lost+found mnt proc run srv tmp var
bin dev home lib64 media opt root sbin sys usr
[root@localhost ~]#

3 less 查看文件的内容分页查看内容
[root@localhost ~]# less anaconda-ks.cfg

4 cat 查看文件的详细内容
[root@localhost ~]# cat tuxwhitebg.jpg

5 查看当前位置 Pwd
Haskell
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd /home/
[root@localhost home]# pwd
/home
[root@localhost home]#
6 ls -- help 寻求帮助的命令操作

7 查看目录下或者本身的信息或者内容 ls ls /
Haskell
[root@localhost home]# ls
goodseeyu hubing lost+found student zhangsan
hello lisi paw wangwu
[root@localhost home]# ls /
afs boot etc lib lost+found mnt proc run srv tmp var
bin dev home lib64 media opt root sbin sys usr
[root@localhost home]#

8 查看目录下所有内容(包含隐藏文档) ls -a

9 查看目录下所有内容(不包含隐藏文档) ls -A 目录

10 查看文档目录下的文档详细信息 ls -l 目录

11 查看目录本身而不是目录下的内容 ls -ld

12 查看文档带上单位显示大小 ls -h

13 切换盘符的命令 cd / . ..
Haskell
[root@localhost ~]# cd /lib
[root@localhost lib]# cd /srv
[root@localhost srv]# cd /etc
[root@localhost etc]# ls

14 绝对路径 相对路径
在 Linux 中,路径是指向文件或目录的位置。路径可以使用绝对路径或相对路径来表示。
绝对路径
绝对路径是指从根目录开始的完整路径。根目录是 Linux 文件系统的顶层目录,通常用 "/" 表示。在绝对路径中,路径名中的每一个目录都用斜杠 "/" 分隔开来。
例如,要访问 /home/user1/testfile 这个文件,其绝对路径就是 /home/user1/testfile。
相对路径
相对路径是相对于当前工作目录的路径。当前工作目录是命令行 shell 所在的目录。在相对路径中,路径名中的每一个目录都用斜杠 "/" 分隔开来。
例如,如果当前工作目录是 /home/user1,且要访问 testfile,可以使用相对路径 ./testfile 或者 testfile。
15 文件文档的管理

16 touch:创建文件名
Haskell
[root@localhost ~]# cd /root/seeyou/
[root@localhost seeyou]# ls
[root@localhost seeyou]# touch hellow.txt
[root@localhost seeyou]# touch hellow.ppt
[root@localhost seeyou]# touch hellow.html
[root@localhost seeyou]# touch good.txt
[root@localhost seeyou]# touch good.docx
17 mkdir:创建文件目录

javascript
[root@localhost seeyou]# mkdir hello
[root@localhost seeyou]# mkdir student
[root@localhost seeyou]# mkdir a/b/c
mkdir: 无法创建目录 "a/b/c": 没有那个文件或目录
[root@localhost seeyou]# mkdir -r a/b/c
mkdir: 不适用的选项 -- r
请尝试执行 "mkdir --help" 来获取更多信息。
[root@localhost seeyou]# mkdir -p a/b/c
[root@localhost seeyou]# ls
a good.docx good.txt hello hellow.html hellow.ppt hellow.txt student
[root@localhost seeyou]#
18 多级目录创建 mkdir -p 目录

19 复制目录 cp 原文件 目标 文件

20 复制目录 cp -r 原目录 目标目录

21 移动文档 mv 原文档 目标文档


22 删除文档命令 rm -f 目标文档

23 删除文件目录命令 rm -rf 目标目录


24 综合练习

25 文档编辑器 Vim 基础操作
Vim:一个高度可定制的文本编辑器,可以通过命令模式和插入模式进行编辑。
Emacs:一个类Unix操作系统上非常强大的文本编辑器,它使用LISP编程语言作为扩展语言。
Nano:一个简单易用的文本编辑器,适用于新手。
Gedit:一个GNOME桌面环境下的文本编辑器,提供基本的编辑功能。
Atom:一个由GitHub开发的跨平台文本编辑器,支持多种编程语言。
Sublime Text:一个流行的跨平台文本编辑器,具有快速、轻便和高度可定制的特点。
Visual Studio Code:一个由微软开发的跨平台文本编辑器,支持多种编程语言和集成开发环境。
26 认识Vim编辑器的操作
启动vim编辑器
在终端中输入
vim
命令即可启动vim编辑器。创建或打开文件
可以在vim命令后面直接跟上文件名,如
vim file.txt
,如果文件存在则会打开,如果文件不存在则会创建该文件并打开。命令模式和插入模式
vim编辑器有两种模式:命令模式和插入模式。
命令模式用于移动光标、复制、粘贴等操作。在命令模式下按下
i
键即可进入插入模式,此时可以开始编辑文件。要返回到命令模式,可以按下ESC
键。保存和退出
在命令模式下,按下
:w
可以保存文件,:q
可以退出编辑器。如果文件已被修改,需要先保存后退出,则可以使用:wq
命令。光标移动
在命令模式下,可以使用以下键盘控制光标移动:
h
:光标左移一格
j
:光标下移一格
k
:光标上移一格
l
:光标右移一格
0
:光标移到行首
$
:光标移到行末
G
:光标移到文件末尾
gg
:光标移到文件开头复制和粘贴
在命令模式下,使用以下命令进行复制和粘贴:
yy
:复制当前行
p
:粘贴复制的内容
- 撤销和重做
在命令模式下,可以使用以下命令进行撤销和重做操作:
u
:撤销上一次操作
CTRL + r
:重做上一次操作
27 vim实操




28 用户的管理 增删改查




root@localhost \~\]# vim /var/www/html/t1.php \[root@localhost \~\]# useradd hellow \[root@localhost \~\]# passwd hellow 更改用户 hellow 的密码 。 新的密码: 无效的密码: 密码少于 8 个字符 重新输入新的密码: passwd:所有的身份验证令牌已经成功更新。 \[root@localhost \~\]# id hellow 用户id=1008(hellow) 组id=1008(hellow) 组=1008(hellow) \[root@localhost \~\]# passwd hellow 更改用户 hellow 的密码 。 新的密码: 无效的密码: 密码少于 8 个字符 重新输入新的密码: passwd:所有的身份验证令牌已经成功更新。 \[root@localhost \~\]# id hellow 用户id=1008(hellow) 组id=1008(hellow) 组=1008(hellow) \[root@localhost \~\]# ls /home/ goodseeyu hello hellow hubing lisi lost+found paw student wangwu zhangsan \[root@localhost \~\]# userdel -r lisi \[root@localhost \~\]# ls /home/ goodseeyu hello hellow hubing lost+found paw student wangwu zhangsan




root@localhost \~\]# id hellow 用户id=1008(hellow) 组id=1008(hellow) 组=1008(hellow) \[root@localhost \~\]# ls /home/ goodseeyu hello hellow hubing lisi lost+found paw student wangwu zhangsan \[root@localhost \~\]# userdel -r lisi \[root@localhost \~\]# ls /home/ goodseeyu hello hellow hubing lost+found paw student wangwu zhangsan \[root@localhost \~\]# gro grodvi groffer grolbp gropdf grotty groupdel groupmod groff grog grolj4 grops groupadd groupmems groups \[root@localhost \~\]# group hello -bash: group:未找到命令 \[root@localhost \~\]# grou \[root@localhost \~\]# gro grodvi groffer grolbp gropdf grotty groupdel groupmod groff grog grolj4 grops groupadd groupmems groups \[root@localhost \~\]# groupadd hello groupadd:"hello"组已存在 \[root@localhost \~\]# groupadd good \[root@localhost \~\]# groupadd see \[root@localhost \~\]# ls / afs boot etc lib lost+found mnt proc root sbin sys usr bin dev home lib64 media opt repos run srv tmp var \[root@localhost \~\]# ls /home/ goodseeyu hello hellow hubing lost+found paw student wangwu zhangsan \[root@localhost \~\]# id hello 用户id=1001(hello) 组id=1001(hello) 组=1001(hello) \[root@localhost \~\]# gpasswd -a hubing see 正在将用户"hubing"加入到"see"组中 \[root@localhost \~\]# id hubing 用户id=1002(hubing) 组id=1002(hubing) 组=1002(hubing),1010(see)
30 切换用户
Haskell
[root@localhost ~]# su - hubing
Welcome to 5.10.0-60.18.0.50.oe2203.x86_64
System information as of time: 2023年 10月 14日 星期六 11:45:39 CST
System load: 0.16
Processes: 169
Memory used: 24.4%
Swap used: 0%
Usage On: 6%
IP address: 192.168.10.223
IP address: 192.168.122.1
Users online: 1
To run a command as administrator(user "root"),use "sudo <command>".
[hubing@localhost ~]$
31 退出 exit
hubing@localhost \~\]$ exit
注销
\[root@localhost \~\]#
**文档的属主 属组 其他权限的操作 读 写 可控制权限操作**
### 32 认识文档权限



### 33 对文档的属主 属组 其他权限操作 chown
#### **33.1 chown 用户**
#### **33.2 chown :用户名**
#### **33.3 chown 用户名:用户组名 文档名**

### 34 文档 可读 可写 可控制
**U:user O:other G:grounp R:read W:writer X:exictue**



**chmod\[ugo\]\[+-=\]\[rwx\] 文档名**
```Haskell
[root@localhost ~]# ls -l a.txt
-rw-r--r--. 1 root root 0 10月 14 11:47 a.txt
[root@localhost ~]# ch
chacl check_lft_balance.pl chkconfig chronyd
chage checkmodule chmem chroot
chardetect checkpolicy chmod chrt
chattr chem choom chsh
chcat chfn chown chvt
chcon chgpasswd chpasswd
chcpu chgrp chronyc
[root@localhost ~]# chmod u+x a.txt
[root@localhost ~]# ls -l a.txt
-rwxr--r--. 1 root root 0 10月 14 11:47 a.txt
[root@localhost ~]# chomod o+xwy a.txt
-bash: chomod:未找到命令
[root@localhost ~]# chomod o+x a.txt
-bash: chomod:未找到命令
[root@localhost ~]# chomod O+w a.txt
-bash: chomod:未找到命令
[root@localhost ~]# chomod g+w a.txt
-bash: chomod:未找到命令
[root@localhost ~]# chmod o+x a.txt
[root@localhost ~]# ls -l a.txt
-rwxr--r-x. 1 root root 0 10月 14 11:47 a.txt
[root@localhost ~]#
```
### 35 **linux 挂载的基础操作**

### 36 手动挂载 mount



### 37 手动挂载综合题

### 38 配置开机自动挂载
1、创建挂载点
[root@svr223 ~]# mkdir -p /repos/openEuler
2、修改配置/etc/fstab
[root@svr223 ~]# vim /etc/fstab
// 设备文件 挂载点 文件系统类型 挂载选项 检查 备份
/dev/cdrom /repos/openEuler iso9660 ro 0 0
[root@svr223 ~]# reboot
3、检查配置
[root@svr223 ~]# mount -a
没有报错代表配置正确
如果有报错代表配置有问题
4、验证
重启之后,查看
reboot:重启
[root@svr223 ~]# reboot
[root@svr223 ~]#
docs images ks repodata TRANS.TBL
EFI isolinux Packages RPM-GPG-KEY-openEuler
常见错误:
[root@svr223 ~]# mount -a
mount: /repos/openEuler: 特殊设备 /dev/cdom 不存在.
mount: /repos/openEuer: 挂载点不存在.
mount: /repos/openEuler: 未知的文件系统类型"iso9960".
mount: /repos/openEuler: 文件系统类型错误、选项错误、/dev/sr0 上有坏超级块、缺少代码页或帮助程序或其他错误.
### 39 **YUM 源的基础操作**
> 1. 查看系统中已有的YUM源列表:yum repolist
> 2. 启用某个YUM源:yum-config-manager --enable repo_name
> 3. 禁用某个YUM源:yum-config-manager --disable repo_name
> 4. 列出某个YUM源的详细信息:yum info repo_name
> 5. 搜索某个软件包:yum search package_name
> 6. 安装某个软件包:yum install package_name
> 7. 更新某个软件包:yum update package_name
> 8. 删除某个软件包:yum remove package_name
> 9. 清除YUM缓存:yum clean all
> 10. 下载某个软件包但不安装:yum download package_name
> 11. 检查某个软件包是否有更新:yum check-update package_name
> 12. 列出已安装的软件包:yum list installed
> 13. 展示某个软件包的安装信息:yum list package_name
> 14. 列出已安装的但是没有被其它软件包所依赖的软件包:yum list extras
> 15. 列出某个软件包的依赖关系:yum deplist package_name
### **40 yum info 软件 显示软件的详细信息**
```
[root@localhost ~]# yum info httpd
Last metadata expiration check: 2:14:26 ago on 2023年10月14日 星期六 09时37分52秒.
Installed Packages
Name : httpd
Version : 2.4.51
Release : 9.oe2203
Architecture : x86_64
Size : 4.6 M
Source : httpd-2.4.51-9.oe2203.src.rpm
Repository : @System
From repo : @commandline
Summary : Apache HTTP Server
URL : https://httpd.apache.org/
License : ASL 2.0
Description : Apache HTTP Server is a powerful and flexible HTTP/1.1 compliant web server.
```
### **41 yum provides 文件名 查看某个我嗯嗯那就是由那个软件包提供的**
```
[root@localhost ~]# yum provides httpd
Last metadata expiration check: 2:14:16 ago on 2023年10月14日 星期六 09时37分52秒.
httpd-2.4.51-5.oe2203.x86_64 : Apache HTTP Server
Repo : repos_openEuler_
Matched from:
Provide : httpd = 2.4.51-5.oe2203
httpd-2.4.51-9.oe2203.x86_64 : Apache HTTP Server
Repo : @System
Matched from:
Provide : httpd = 2.4.51-9.oe2203
```
### **42 yum -y install 软件名 :安装软件**
[root@localhost ~]# yum -y install httpd
Last metadata expiration check: 2:16:10 ago on 2023年10月14日 星期六 09时37分52秒.
Dependencies resolved.
===============================================================================================================
Package Architecture Version Repository Size
===============================================================================================================
Installing:
httpd x86_64 2.4.51-5.oe2203 repos_openEuler_ 1.3 M
Installing dependencies:
mod_http2 x86_64 1.15.25-1.oe2203 repos_openEuler_ 126 k
Downgrading:
httpd-filesystem noarch 2.4.51-5.oe2203 repos_openEuler_ 11 k
httpd-tools x86_64 2.4.51-5.oe2203 repos_openEuler_ 71 k
Transaction Summary
===============================================================================================================
Install 2 Packages
Downgrade 2 Packages
Total size: 1.5 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
### **43 yum -y remove 软件名 :卸载软件**
[root@localhost ~]# yum -y remove httpd
Dependencies resolved.
===============================================================================================================
Package Architecture Version Repository Size
===============================================================================================================
Removing:
httpd x86_64 2.4.51-9.oe2203 @@commandline 4.6 M
Removing dependent packages:
mod_http2 x86_64 1.15.25-1.oe2203 @@commandline 329 k
Transaction Summary
===============================================================================================================
Remove 2 Packages
Freed space: 4.9 M
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: httpd-2.4.51-9.oe2203.x86_64 1/1
Running scriptlet: httpd-2.4.51-9.oe2203.x86_64 1/2
Removed /etc/systemd/system/multi-user.target.wants/httpd.service.
```
```
### **44 yum -y reinstall 软件名:重装软件**
[root@localhost ~]# yum -y reinstall httpd
Last metadata expiration check: 2:18:09 ago on 2023年10月14日 星期六 09时37分52秒.
Dependencies resolved.
===============================================================================================================
Package Architecture Version Repository Size
===============================================================================================================
Reinstalling:
httpd x86_64 2.4.51-5.oe2203 repos_openEuler_ 1.3 M
Transaction Summary
===============================================================================================================
Total size: 1.3 M
Installed size: 4.6 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
*** ** * ** ***
### 45 LAMP 环境的安装
### 

```css
// 卸载之前的Apache web服务器httpd,防止与之后的LAMP环境冲突
[root@svr223 ~]# yum -y remove httpd
[root@svr223 ~]# pwd
/root
[root@svr223 ~]# ls
anaconda-ks.cfg lamp_oe2203_pkgs
[root@svr223 ~]# ls lamp_oe2203_pkgs/
apr-1.7.0-4.oe2203.x86_64.rpm
apr-util-1.6.1-12.oe2203.x86_64.rpm
git-2.33.0-3.oe2203.x86_64.rpm
httpd-2.4.51-9.oe2203.x86_64.rpm
...
```
安装软件包
```
[root@svr223 ~]# yum -y install httpd mariadb-server php-fpm php-mysqlnd
```
使用如下方式安装:
```
[root@svr223 ~]# yum -y install ./lamp_oe2203_pkgs/*.rpm
```
检查安装的软件包:

```css
httpd:Apahce web应用服务器
mariadb-server:数据库服务器
php-fpm:php解析器
php-mysqlnd:php操作数据库程序
[root@svr223 ~]# yum list httpd mariadb-server php-fpm php-mysqlnd
Last metadata expiration check: 2:14:09 ago on 2023年04月19日 星期三 15时24分30秒.
Installed Packages
httpd.x86_64 2.4.51-9.oe2203 @@commandline
mariadb-server.x86_64 4:10.5.16-1.oe2203 @@commandline
php-fpm.x86_64 8.0.0-10.oe2203 @@commandline
php-mysqlnd.x86_64 8.0.0-10.oe2203 @@commandline
[root@svr223 ~]#
```

```Haskell
systemctl:系统控制器 控制服务的开启/关闭/设置成开机自启/禁止开机自启
system:系统
ctl:controller 控制器
start:开始/开启 stop:停止 is-active:是否活跃/是否开启 active:活跃/开启 inactive:不活跃/关闭 restart:重新启动 type:类型/列出 service:服务
status:状态 enable:开启/开机自启 /now:现在/立即/disable:禁止
systemctl start