Linux operating system learning, Linux basic commands

Table of contents



friendly reminder


First look at the article directory to get a general understanding of the structure of the article's knowledge points. Click on the article directory to jump directly to the specified location of the article.

Chapter 1, Linux Introduction and Installation

1.1) Introduction and classification of Linux

①Linux is an open source and free operating system based on Unix. Due to the stability and security of the system, it has become the best operating system environment for program code to run.
②Different Linux distributions can be divided into
1) Ubuntu: Ubuntu
2) Red Hat: RedHat
3) CentOS
4) Butterfly: Debain
5) SySE
6) Red Flag Linux: domestic

1.2) Install VMware virtual machine, install CentOS 7 in the virtual machine

Read my article, click to jump: Install Linux on a VMware virtual machine

Chapter 2, Detailed Explanation of Linux IP Address Configuration in Virtual Machine

2.1) What is an IP address and how to check it

The ip address is the meaning of the Internet Protocol address, and it is also translated as the Internet Protocol address. The IP address is
a unified address format provided by the IP protocol. It assigns a unique logical address to each network and each host on the Internet to shield the difference in physical addresses.


How to check the ip address of your computer: start - run - enter "cmd", open the command line, enter "ipconfig", press enter

insert image description here

2.2) What are the requirements for the IP address setting of Linux in the virtual machine NAT mode

①Selecting NAT mode during installation means using the host machine (local machine) to create a virtual network card VMNet8, create a virtual switch to connect to this network card, and then use this virtual switch to access the Internet. Use NAT mode to indicate that it is created inside the computersubnet, the network where the virtual machine is located is the subnet of the host machine.
②The network settings can be changed in the Edit→Virtual Network Editor of VMWare.
insert image description here
③ To manually set the subnet ip address of the virtual machine Linux, you must ensure:
(1) Subnet ip address: the first and second paragraphs (192.168.) need to be consistent with the host (this machine), and the third paragraph must be the same as the host (This machine) is inconsistent, write 0 in the fourth paragraph.
(2) Mask: 255.255.255.0.
(3) NAT Gateway: The first three sections must be consistent with the subnet, and the last section should be filled with a number between 1 and 254.
(4) DHCP: Dynamic Host Configuration Protocol, which is a LAN network protocol and uses UDP protocol to work. The main purpose is to quickly and automatically assign IP addresses to the network. The first three segments must be consistent with the subnet, and the last address range cannot include the gateway address.
(5) dns: You can directly write the free DNS address: 114.114.114.114
insert image description here

2.3) Use the editing command in Linux to configure the network card information file


①Use the editing command in Linux to configure the network card information: vi/vim

When we edit a file, we can do this:

vi /etc/sysconfig/network-scripts/ifcfg-ens33
means:
/ indicates the root directory
/etc indicates the configuration file Directory
/etc/sysyconfig directory contains the Linux system configuration file
network-scripts directory is the network card configuration folder
ifcfg-ens33 is the network card of my machine, but the name of each network card may be different


[root@localhost /]# vi /etc/sysconfig/network-scripts/ifcfg-ens33	#以下是原文件的网卡信息

TYPE=Ethernet	#网卡类型:以太网
PROXY_METHOD=none	#代理方式:关闭
BROWSER_ONLY=no	  #只是浏览器:否
BOOTPROTO=dhcp	#网卡配置方式:dhcp(自动获取ip)
DEFROUTE=yes	#默认路由:开启
IPV4_FAILURE_FATAL=no	#IPV4致命错误检测:不开启
IPV6INIT=yes	#自动初始化IPV6:是
IPV6_AUTOCONF=yes	#自动配置IPV6:是
IPV6_DEFROUTE=yes	#IPV6默认路由:不开启
IPV6_FAILURE_FATAL=no	#IPV6致命错误检测:不开启
IPV6_ADDR_GEN_MODE=stable-privacy	#IPV6生成“stable-privacy”的模型
NAME=ens33	#网卡别名
UUID=7a2ccac9-7a0c-46cb-abd2-fe82ead125bb	#唯一标识码
DEVICE=ens33	#网卡名称
ONBOOT=no	#是否要设置为开机启动
~
~
"/etc/sysconfig/network-scripts/ifcfg-ens32" 15L, 279C	
)

② After entering the network card file, pressiStart editing, and start modifying the configuration network card information as follows: Usually, you need to set a fixed ip address in order to use the network for communication in the future (such as ssh, nfs, etc.).

[root@localhost /]# vi /etc/sysconfig/network-scripts/ifcfg-ens33	#配置网卡信息
TYPE=Ethernet	
PROXY_METHOD=none	
BROWSER_ONLY=no	  
BOOTPROTO=static	#需要修改的:将dhcp模式修改为static模式
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=7a2ccac9-7a0c-46cb-abd2-fe82ead125bb	
DEVICE=ens33	
ONBOOT=yes	#需要修改的:设置网卡为开机自启动

#此处为添加内容
IPADDR=192.168.10.12	#需要添加的:设置IP地址
NETMASK=255.255.255.0	#需要添加的:设置对应子网掩码
GATEWAY=192.168.10.254	#需要添加的:设置对应网关
DNS1=114.114.114.114	#需要添加的:设置首选DNS

③ After editing: Press Esc to exit editing
Input: wq!——” means save and exit
Input: q! ——” means exit without saving

insert image description here
④ Restart the virtual machine to check whether it is successful Command: reboot

Chapter 3, the use of xshell tools and xftp

3.1) xshell download and installation

①Used to remotely operate the Linux virtual machine system,
download the free version from the official website of the two tools: https://www.xshell.com/zh/

insert image description here
②Click to download, double-click the .exe file to install directly
insert image description here
③Always go to the next step to install directly
insert image description here

3.2) xshell connection

①File—"New Session—"Enter the IP address of the virtual machine—"Connect
insert image description here
②Enter the Linux account to confirm and enter the password
insert image description here
to connect and then you can remotely control the Linux system in xshell
insert image description here

3.3) xftp download installation and connection

same as xshell

Chapter 4, Firewall and User Setting Commands

4.1) View and close the firewall

Check the firewall status: systemctl status firewalld
insert image description here
temporarily close the firewall (restart the system to restore):
systemctl disable firewalld.service

insert image description here

Disable firewall permanently (does not restore after reboot):
systemctl disable firewalld.service

4.2) Users

①Add user
useradd 用户名

② Add a password to the newly added user

passwd 用户名
输入密码,再一次输入密码确认

switch user

su	-用户名

View current users

whoami

③Delete a user

userdel 用户名

④ View a user's detailed information

cat /etc/passwd

⑤ View the user's shadow file

cat /etc/shadow

⑥ View user groups

cat /etc/group

⑦Add user group

groupadd sh2304

⑧Add user bao to user group sh2304

usermod -G sh2304 bao

⑨Delete a user group

groupdel 用户组名称

Chapter 5, Basic Command Encyclopedia

5.1) System commands and directory structure

5.1.1) System commands

#用于显示或配置网络设备(网络接口卡)的命令
	ifconfig
# 查看ip地址
	ip addr
# ping网络(测试网络连通)
	ping 目标机器的ip
# 查看系统时间
	date
# 注销
	logout
# 关机命令
	init 0
	shutdown now
# 重启命令
	init 6
	reboot
# 清屏命令
	快捷键Ctrl+L
	clear
# 帮助信息man
	#查看ls命令的选项:
	man ls
	#查看配置信息“
	man /etc/services
	

5.1.2) Directory structure


Directory meaning:

/etc/sysconfig/network-scripts/ifcfg-ens33

/ 表示根目录
/etc表示配置文件目录
/etc/sysyconfig目录包含了Linux的系统配置文件
network-scripts目录是网卡配置文件夹
ifcfg-ens33网卡文件

5.1.3)编辑命令vi/vim

①进入文件

#进入文件
vim 文件名


②按i编辑进入编辑模式(插入模式),
insert image description here


③按Esc键进入最后行模式

:q!  #退出不保存
:wq! #退出并保存

5.2)文件操作命令(区分大小写)

5.2.1)查看查找文件和文件信息,切换目录

查看文件列表

# 查看当前目录下的文件列表
	ls
# 查看指定目录下的文件
	ls /
# 查看详细信息,元数据信息(用户、组、大小、创建时间、权限信息、文件类型)
	ls -l
# 查看隐藏文件
	ls -a 
# 参数并用,查看根目录下所有的文件或目录的详细信息
	ls -la
	

查找文件

# 语法
	find 搜索路径 -name "文件名关键词"
# 例子
	find / -name "passwd"
	find / -name "ifcfg-*"

查找文件内容

# 语法
	grep -参数 要查找的目录范围
	# 参数
	-n 显示查找结果所在行号
	-R 递归查找目录下的所有文件
# 例子
	grep aries /etc
	grep aries /etc/passwd
	

切换目录

#  切换目录
	cd 目标文件夹
# 绝对路径切换
	cd 绝对路径
# 相对路径切换
	cd 相对路径
# 切换上一级目录
	cd ..
# 切换根目录目录
	cd /

查看当前命令所在目录,显示当前目录结构

[root@centos7 network-scripts]# pwd
/etc/sysconfig/network-scripts
# 特殊目录符号
	~ 当前用户的home目录
	. 当前目录
	.. 上一级目录

查看文件信息

# 查看文件中的全部信息(适合查看小文档)
	cat 文件名

分页查看文件信息

# 以分页的方式浏览文件信息(适合查看大文档),进入浏览模式
	more 文件名
	less 文件名
# 浏览模式快捷键
	↑ #上一行
    ↓ #下一行
    G #最后一页
    g #第一页
    空格 #下一页
    /关键词 #搜索关键词
# 退出浏览模式,回到Linux命令行模式
    q #退出

查看文件信息前多少行,后多少行

#head命令:查看一个文件的前多少行
head -30 文件名
# 实时滚动显示文件的最后10行信息(默认10)
tail -f 文件名
# 显示文件的最后20行信息
tail -n 20 文件名
tail -n -20 文件名
# 显示文件信息从第20行至文件末尾
tail -n +20 文件名

5.2.2)新建/删除/复制/移动修改文件和文件夹,获取文件数字签名

新建文件夹和文件

# 在当前位置新建文件夹
	mkdir 文件夹名
# 在指定目录位置,创建文件夹,并创建父文件夹
	mkdir -p /a/b/文件夹名
# 在当前目录下新建文件
	touch 文件名

删除文件

# 删除文件
	rm 文件
# 删除文件夹
	rm -r 文件夹
# 强制删除不询问
	rm -rf 文件

复制文件

# 拷贝文件
	cp 原文件  新文件
# 拷贝文件夹
	cp -r 源文件夹 新文件夹

移动(剪切)和修改文件名

# 移动源文件到目标文件夹中
	mv 文件  文件夹
# 修改文件A的名字为文件B
	mv 文件A 文件B

获取文件的数字签名

md5sum 文件名
# 简介
1. 数字签名,又称数字指纹
2. 可以验证文件是否被修改
3. 一个文件通过计算得到的一串字符串,文件内容的唯一标记(文件内容不变,指纹不会变)

5.2.3)压缩和解压缩文件

gzip命令:只能压缩文件,不能压缩目录,压缩后的格式为.gz,不保留原文件不常用
insert image description here

tar命令:
-z:打包的同时压缩
-c:产生.tar的压缩文件
-v:显示压缩的过程信息
-f:指定压缩(后)的压缩文件名称
-x:解压.tar.gz压缩文件
-C:指定解压到哪个路径的目录下
压缩语法:

tar -zcvf 压缩后文件名 被压缩文件

解压缩语法:

tar -zxvf 压缩文件名 -C 解压后文件所在目录

5.2.4)grep跟管道符|配合使用,查找文件中的内容。

insert image description here

5.2.5)文件权限介绍与设置文件权限

①设置权限命令必须是管理员用户操作:chmod
②如图为权限含义,从左到右共有十个字段

insert image description here

①第1个字段:-代表文件,d代表目录
②第234字段(u):表示所有者对文件的操作权限
 r:读  
 w:写  
 x:excute可执行   
 -:代表没有权限
③第567个字段(g):表示所有组对文件的操作权限
④第8910、字段(o):表示其它人对文件的操作权限
⑤运算符:
	- 删除权限
	+ 添加权限
	= 赋值权限

③设置所有者对hello.txt文件的x(可执行)权限

chomod u+x hello.txt

insert image description here
④设置所有组对hello.txt文件的w(写)权限

chomod g+w hello.txt

insert image description here
⑤同时设置test01.txt文件的所有组和其他人的w(写)权限

chomod o+w,g+w test01.txt

insert image description here

5.3)软件包管理命令:rpm和yum

5.3.1)rpm命令

RPM:ReaHalt软件包管理工具。用于互联网下载包及安装工具,是一个软件包管理工具,缺陷是依赖性非常大,不管是卸载还是安装包与包之间的依赖性非常大。
①rpm命令

#查看所有安装的软件包
	 rpm -qa
#查看系统中是否已安装的过该软件
	rpm -qa 软件包名
#按名称过滤查找
	rpm -qa | grep:软件包名
#安装rpm软件
  语法:rpm -ivh xxx.rpm
#卸载软件(存在依赖)
	  rpm -e 软件名

5.3.2)yum命令

yum:shell前端的管理器,基于rpm包管理的,解决了rpm包管理的依赖问题,前提条件是可以正常联网。

①yum基础命令

## 列出所有可以安装的软件包
	yum list
## 安装软件
	yum install -y 软件名
## 卸载软件
	yum remove 软件名
## 查找软件包
	yum search all 软件名

②举例安装火狐浏览器

#安装命令
yum install firefox

#提示y/d/n时
y:下载安装
d:只下载不安装
n:不安装

第六章、Linux中安装软件

6.1)安装Java的JDK

6.1.1)关闭防火墙,传输jdk压缩包到Linux虚拟机

①永久性关闭防火墙

systemctl disable firewalld.service

#重启Linux系统让其生效

reboot

②登录xftp传输JDK1.8的.tar压缩文件,直接拖拽文件就可以将本机文件传输到虚拟机root文件夹下
insert image description here
③解压jdk的压缩文件到/usr/local/java目录下

tar -zxvf jdk-8u77-linux-x64.tar.gz -C /usr/local/java

6.1.2)配置java环境变量

①编辑 /etc/profile 文件:

 vim /etc/profile

②在文件最后添加如下配置信息

JAVA_HOME=/usr/local/java/jdk1.8.0_77
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH

③重新加载 /etc/profile 文件

source /etc/profile

④使用Javac命令A验证是否配置成功
insert image description here

6.2)安装tomcat

6.2.1)关闭防火墙,传输tomcat压缩包到Linux虚拟机

①永久性关闭防火墙

systemctl disable firewalld.service

#重启Linux系统让其生效

reboot

②登录xftp传输tomcat.tar压缩文件,直接拖拽文件就可以将本机文件传输到虚拟机root文件夹下
insert image description here
③解压tomcat的压缩文件到/usr/local/tomcat目录下

tar -zxvf apache-tomcat-9.0.37.tar.gz -C /usr/local/tomcat

6.2.2)启动tomcat

①进入到解压文件夹的bin目录

cd /usr/local/tomcat/apache-tomcat-9.0.37/bin

②运行./startup.sh命令启动tomcat
此时…/logs目录会生成catalina.out文件

./startup.sh

insert image description here
tomcat结束命令:

./shutdown.sh

启动时查看日志命令:

./startup.sh && tail -f ../logs/catalina.out

6.3)安装MySQL5.6.34不同版本安装方式不同,很多坑

6.3.1)关闭防火墙,传输MySQL压缩包到Linux虚拟机

①永久性关闭防火墙

systemctl disable firewalld.service

#重启Linux系统让其生效

reboot

②登录xftp传输MySQL压缩文件,直接拖拽文件就可以将本机文件传输到虚拟机/usr/local文件夹下
insert image description here

③Unzip the MySQL compressed file to the /usr/local directory

tar -zxvf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz -C /usr/local/MySQL

④Rename to mysql

mv mysql-5.6.34-linux-glibc2.5-x86_64 mysql

6.3.2) Uninstall mariadb, delete my.cnf

①Query the installed mariadb and uninstall mariadb

rpm -qa|grep mariadb

rpm -e --nodeps 文件名

insert image description here
②Delete my.cnf in the etc directory (no can be ignored)

rm /etc/my.cnf

6.3.3) Create MySQL user group

① Create a mysql user group

groupadd mysql

②Create a user named mysql and join the mysql user group

useradd -g mysql mysql

6.3.4) Configure my.cnf

①Copy a copy of my-default.cnf under /usr/local/mysql/support-files to /etc and rename my.cnf

cp ./mysql/support-files/my-default.cnf /etc/my.cnf

②Edit my.cnf in the /etc directory

vi /etc/my.cnf

③Start configuring my.cnf, copy the following code to the last line, save and exit

[mysql] # 设置mysql客户端默认字符集 
default-character-set=utf8 
socket=/var/lib/mysql/mysql.sock
[mysqld] skip-name-resolve
#设置3306端口 
port = 3306 
socket=/var/lib/mysql/mysql.sock 
# 设置mysql的安装目录 
basedir=/usr/local/mysql 
# 设置mysql数据库的数据的存放目录 
datadir=/usr/local/mysql/data 
# 允许最大连接数 
max_connections=200 
# 服务端使用的字符集默认为8比特编码的latin1字符集 
character-set-server=utf8 
# 创建新表时将使用的默认存储引擎 
default-storage-engine=INNODB 
lower_case_table_name=1 
max_allowed_packet=16M

As shown in the picture:
insert image description here

6.3.5) Modify the current directory owner to mysql user

①Enter the installation mysql software directory

cd /usr/local/mysql

②Change owner

chown -R mysql:mysql ./

③Install the autoconf library

yum -y install autoconf

④ Install the database in the mysql directory

./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

⑤In the mysql directory, modify the owner of the current data directory to be the mysql user

chown -R mysql:mysql data

⑥ Grant the maximum authority to my.cnf

chmod 777 /etc/my.cnf

⑦Set the boot self-starting service control script in the mysql directory

cp ./support-files/mysql.server  /etc/rc.d/init.d/mysqld

⑧ Increase mysqld service control script execution authority

chmod +x /etc/rc.d/init.d/mysqld

⑨Add mysqld service to system service

chkconfig --add mysqld

⑩ Check whether the mysqld service has taken effect

chkconfig --list mysqld

The successful result is as follows
insert image description here

6.3.6) Configure environment variables

①Edit the profile file

vi /etc/profile

② Add the mysql bin directory to the PATH environment variable, save and exit

export PATH=$PATH:/usr/local/mysql/bin

③ Refresh resources

source /etc/profile

6.3.7) Start MySQL to set a password and make a remote connection

① start mysqld

service mysqld start

②Log in to mysql with the root account, there is no password by default, just press Enter

mysql -uroot -p

③Set your own password, here is root

mysql> set password=password("root");

insert image description here
④ Allow remote login

mysql> grant all privileges on *.* to'root' @'%' identified by 'root';
mysql> flush privileges;

⑤Use navicate on windows to try to connect to mysql
insert image description here

Guess you like

Origin blog.csdn.net/baomingshu/article/details/131972605