Learn Linux easily in a few minutes (easy to understand, detailed and comprehensive)

Chapter 1 Simple use of linux

1.1 Composition of Linux

1.Linux kernel: The kernel is the core of the system and is the core program for running programs and managing hardware devices such as disks and printers.
2. File system: A method of organizing files stored on storage devices such as disks. Linux can support a variety of currently available file systems, such as
ext4, FAT, VFAT, ISO9660, NFS, SMB, etc.
3. Shell: Shell is the user interface of the system, providing an interface for users to interact with the kernel.
Applications: including text editors, programming languages, X Window, office suites, Internet tools, databases, etc.
The operating interface of Linux is often called Shell. Shell is the interface (graphics, characters) provided by the operating system to users. It provides
an interface for users to interact with the kernel. When the user issues instructions (commands or mouse operations), these instructions are first sent to the Shell. The
Shell translates the user instructions and transmits them to the kernel, and then the kernel controls the work of the hardware. Then the kernel sends the working status of the hardware to
the Shell, and the Shell returns the working information and status of the hardware.
Classification of Shell:
Shell with graphical interface: KDE, GNOME
Shell with character interface: bash, etc.
(1) Check the current Linux distribution information

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 8.3.2011

(2) Check the kernel version

[root@localhost ~]# uname -r 
4.18.0-240.el8.x86_64 

The Linux kernel version number has gone through three different naming schemes:
Versions before 1.0 ~ 2.6: ABC
A – a major version number with substantial changes;
B – a minor version number with some major modifications
C – refers to a minor revision The revision number, C is the odd-numbered development version, and the even-numbered version is the stable version.

Versions 2.6.0.0~2.6.39.4: ABCD
A and B – are fixed to 2 and 6 respectively;
C – is the kernel version;
D – security patch number.

Starting from version 3.0: XAB
X – major version number, currently 3 or 4;
A – kernel version, B – security patch.
Starting from this version, even numbers represent stable versions and odd numbers represent development versions. The naming method
mainline – mainline version (represents the version currently being developed by the main force or development version)
stable – stable version
longterm – long-term support version
EOL (End of Life) – an older version that has been discontinued from technical support.
(3) Check the type of shell

方法1:cat /etc/shells 
[root@localhost ~]# cat /etc/shells 
/bin/sh 
/bin/bash 
/usr/bin/sh 
/usr/bin/bash 
方法2:chsh -l 
[root@localhost ~]# chsh -l 
/bin/sh 
/bin/bash 
/usr/bin/sh 
/usr/bin/bash 
[root@localhost ~]# 

(4) View the current default shell

`[root@localhost ~]# echo $SHELL 
/bin/bash

(5) Shell prompt: # and $
. For ordinary users, the default prompt of Base shell is the dollar sign $;
for super users (root users), the default prompt of Bash Shell is the pound sign #.
Ordinary user login: [当前登录用户@主机名 当前工作目录 ] $
Root user login: [root@主机名 当前工作目录 ] # (6)使用命令重启和关闭linux操作系统:
Restart: reboot, shutdown -r now
Shutdown: shutdown -h now, poweroff
(6) Use the command to restart and shut down the Linux operating system:
Restart: reboot, shutdown -r now
Shutdown: shutdown -h now , poweroff shutdown -r +30 'the system will reboot' After another 30 minutes, the system will reboot and display the following message to all
online users
(7) Check the network card information and obtain the IP address

#获取ip地址 [root@localhost ~]# dhclient #如果提示没有该命令,则需要先装包才能使用,可使用nmcli命令获 取地址 
[root@localhost ~]# nmcli con up ens160 
#查看ip地址 [root@localhost ~]# ip a 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 
	link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 
	inet 127.0.0.1/8 scope host lo 
		valid_lft forever preferred_lft forever 
	inet6 ::1/128 scope host 
		valid_lft forever preferred_lft forever 
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 
	link/ether 00:0c:29:53:e2:2c brd ff:ff:ff:ff:ff:ff 
	inet 192.168.168.128/24 brd 192.168.168.255 scope global dynamic noprefixroute ens160 
		valid_lft 1284sec preferred_lft 1284sec 
	inet6 fe80::1d40:7cea:e3be:32d9/64 scope link noprefixroute 
		valid_lft forever preferred_lft forever 
#注:lo网卡是环回网卡,主要用来本地测试;ens160才是我们远程连接的网卡。

1.2 Remotely connect to Linux server

The method of remote connection to the Linux server: classified by the type of display, which can be divided into two types: character interface and graphical interface. Character interface software
includes SecureCRT, PUTTY, xshell, mobaxterm, etc.; graphical interface software includes Xmanager, Xdmcp and VNC software, etc.

1.2.1Xshell remote connection to Linux

The method of remote connection to the Linux server: classified by the type of display, which can be divided into two types: character interface and graphical interface. Character interface software
includes SecureCRT, PUTTY, xshell, mobaxterm, etc.; graphical interface software includes Xmanager, Xdmcp and VNC software, etc.
(1) Double-click the desktop Xshell icon to start the Xshell program.
Manually enter the host IP address in this window , enter the Enter key, and then enter your root user's password ssh root@linuxin the pop-up password prompt window , and you can successfully log in as the root user. Manually enter it in this window , enter the Enter key, and then enter your ordinary user password in the pop-up password prompt window , and you can successfully log in as an ordinary user.

ssh 普通用户名@linux主机IP地址

1.2.2 Use MobaXterm to connect to Linux remotely

Please add image description
Please add image description
Please add image description
Please add image description

1.3 Control the server through remote software

The remote connection is successful as shown in the figure below:
Please add image description
(1) Switch to the ordinary user you added when installing the system.

[root@localhost ~]# su - centos
 Last login: Mon Jun 6 15:15:20 CST 2022 on pts/0 
 [centos@localhost ~]$ 

#输入exit退出 [centos@localhost ~]$ exit 
logout 
[root@localhost ~]# 

#查看当前登录的用户 
[root@localhost ~]# whoami 
root

(2) To modify the host name, you need to reconnect remotely to take effect.

[root@localhost ~]# hostname server             #临时修改,重启linux系统之后失效 
[root@localhost ~]# hostnamectl  set-hostname  server #永久生效,修改的是文件内容。重启linux系统后依旧生效 
#查看主机名配置文件 
[root@localhost ~]# cat /etc/hostname 
server

(3) View the current working directory:pwd

[root@localhost ~]# pwd 
/root 
[root@localhost ~]# su - centos 
Last login: Mon Jun 6 15:16:56 CST 2022 on pts/0 
[centos@server ~]$ pwd 
/home/centos 
注意:windows和linux系统的目录路径表示的不同

(4) Change the current working directory, that is, switch directories
· Absolute path (path starting with /)
· Relative path (path not starting with /)

[root@localhost ~]# cd / 
[root@localhost /]# cd - 注:该操作会让你回到上一次切换的目录下 
/root 
[root@localhost ~]# 

[root@localhost /]# cd /home 
[root@localhost home]# cd /home/centos 
[root@localhost centos]# cd ~ 注:~代表当前用户的家目录,当前用户为root,则代表为 root用户的家目录 
[root@localhost ~]# cd .. 注:..代表当前工作目录的上一级目录 
[root@localhost /]# cd . 注:.代表当前工作

(5) Change password

[root@localhost ~]# passwd 
Changing password for user root. 
New password: 
BAD   PASSWORD: The password is shorter than 8 characters 
Retype new password: 
passwd: all authentication tokens updated successfully. 
[root@localhost ~]# passwd centos 
Changing password for user centos. 
New password: 
BAD   PASSWORD: The password is shorter than 8 characters 
Retype new password: 
passwd: all authentication tokens updated successfully. 
[root@localhost ~]# passwd -d centos #删除centos用户的密码

Analysis: The similarities and differences between ordinary users and root users in changing passwords.
Ordinary users: 1. Need to enter the original password 2. Username cannot be specified when changing the password 3. It needs to be longer than 8 characters and cannot be systemized

1.4Reset root password

rhel8/centos8 reset root password

method one:

Step 1: Restart the system and press the e key on the interface shown below.
Please add image description
Step 2: Find the linux line, enter rd.break after the space at the end
Please add image description
and press ctl+x to enter the following interface:
Then enter

mount  -o  remount,rw  /sysroot
chroot /sysroot
passwd root

As shown below:
Please add image description
After completing the previous steps, enter to modify the password.
Note: When writing a new password, the page will not display the number you entered (as shown below)
and then enter:

touch /.autorelabel

Look at the picture below:
Insert image description here
Please add image description
After changing the password, you have to enter "exit" twice
and then log in automatically. It takes a long time, so wait patiently.

Method Two:

Similar to method one, but different in step two.
After entering the following page, change "ro" in the picture below to "rw", and then add "init=/bin/sh" at the end
as shown below:
Please add image description
Then enter two lines of code, as shown below:
Please add image description

The latter method is the same.

Chapter 2 Executing commands in linux

2.1 Command format

Command format: Main command options parameters (operation objects)
commands are divided into two categories:
       built-in commands (builtin): commands that come with the shell program
       External commands: independent executable program files, the file name is the command name
Options: specify the command The running characteristics indicate which function code in the command is to be run.
       Short options: For example: -l, -d. If the same command uses multiple short options at the same time, most of them can be merged. [Note: Some command options do not have -]
       long options: such as –help, –human-readable
parameter: the object of the command, that is, what the command takes effect on.
       Different commands have different parameters.
       Some options can take parameters, some options can take no parameters
       , and some commands can take multiple parameters at the same time. Multiple parameters should be separated by blank characters. Terminate
the current command:
       press [Ctrl+C] to interrupt. The command being executed
has two kinds of completion:
       Completion command: After entering the first few characters of the command keyword, press the Tab key to realize automatic completion of the command. Completion of
       file name and directory name: After entering the first few characters of the file, Press the tab key to automatically complete

[root@localhost ~]# passwd -d centos 
[root@localhost ~]# cat /etc/redhat-release 
[root@localhost ~]# uname -r 
4.18.0-240.el8.x86_64

View bash internal command help

[root@node13 ~]# help cd

command --help

[root@node13 ~]# cat — —help 
示例如下:cat [OPTION]... [FILE]... 表明cat后面可以加上多个可选的选项以及多个可选的文件参数

下面是对于命令的语法的一些符号的说明: 
[] :表示的是可选
 ...: 表示的可以存在多个参数 
 |   : 表示是可选的 
 <>:  必填 
 {
    
    }:表示作为一个整体存在的

man is used to provide online help, and the usage permissions are for all users. You can use the man command to read the help information, which is very convenient.
It is useful
in the interface of the man command help information. The common operation buttons included are as follows:

button effect
Space bar, PaGe down Turn down one page
PaGe up,b turn one page up
home Go directly to homepage
end Go directly to the last page
/ Turn down one page
Space bar, PaGe down Search for a keyword from top to bottom, such as "/linux"
Search for a keyword from bottom to top, such as "?linux"
n Locate the next searched keyword
N Locate the last searched keyword
q Exit help document

The structure of the help information for the man command is as follows:

Structure name Representative meaning
NAME command name
SYNOPSIS General usage of parameters
DESCRIPTION Introduction
EXAMPLES Demo (with simple instructions)
OVERVIEW Overview
DEFAULTS Default function
OPTIONS Specific available options (with introduction)
ENVIRONMENT environment variables
FILES Files used
SEE ALSO relating documents
HISTORY Maintenance history and contact information

Several parts of the man manual

区段1:用户指令,查看命令的帮助 
区段2:系统调用,查看可被内核调用的函数的帮助 
区段3:程序库调用,查看函数和函数库的帮助 
区段4:设备,查看特殊文件的帮助(主要是/dev目录下的文件) 
区段5:文件格式,查看配置文件的帮助 
区段6:游戏,查看游戏的帮助 
区段7:杂项,惯例与协议等,例如Linux文件系统、网络协议、ASCII code等等的说明 
区段8:系统指令,查看系统管理员可用的命令的帮助 
区段9:内核内部指令,查看内核相关文件的帮助 

使用如下命令可以知道某个命令在man的哪个区段有相关帮助文档: 
[root@node13 ~]# whatis man 
man (7) - macros to format man pages 
man (1) - an interface to the on-line reference manuals 
man (1p) - display system documentation 
[root@node13 ~]# man -f man 
man (7) - macros to format man pages 
man (1) - an interface to the on-line reference manuals 
man (1p) - display system documentation 

[root@node13 ~]# man 1 man 
[root@node13 ~]# man 7 man

info page
The uses of info and man are actually similar. They are both used to query the usage of commands or the format of files. But unlike the man page , the info page splits the file data into paragraphs. Each paragraph is written on its own page, and there are "hyperlinks" similar to web pages
in each page to jump to each page.
Among different pages, each independent page is also called a node.

However, the description file of the target data you want to query must be written in the format of info to use the special functions of info (such as hyperlinks
). The file that supports the info command is placed in the /usr/share/info/ directory by default.

Keys that can be used in the info page:

shortcut key effect
up arrow move up one line
down arrow Move down one line
PgUp turn one page up
PgDn Turn down one page
Tab Switch between nodes with the "*" symbol
Enter Enter the subpage with the "*" symbol to view detailed help information
u Go to the previous level of information
n Go to the next section of information
p Return to the previous section of information
s or / Use keyword search in info page
View help information
q Exit info

2.2 date command

The date command is used to display or set the system time and date. The syntax format is:date [OPTION]... [+FORMAT]

Users only need to enter the parameters starting with + after the powerful date command, and the system time or date can be output in the specified format.
In this way, backup data command can be combined with the time output in the specified format during daily work. Come together. For example, the packaged files
are automatically packaged into "backup-2020-9-1.tar.gz" in the "year-month-day" format. Users only need to glance at the file name to roughly understand
each file. It's time for backup.

Common parameter formats and functions in the date command

parameter effect
%Y Complete year (example: 2020)
%m Month (1~12)
%d Day of the month
%H Hours (00~23)
%M Minutes (00~59)
%j What day of the year is it?

The date command to view the current system time in the default format is as follows:

[root@kongd ~]# date 
Sat Sep 5 09:13:45 CST 2020

The parameter %j in the date command can be used to check what day of the year today is. This parameter can well distinguish between old and new backup times, that is,
the larger the number, the closer it is to the current time. The usage of this parameter and the display results are as follows:

[root@kongd ~]# date "+%j" 
306

The date command to view the current system time in the format of "year-month-day hour:minute:second" is as follows:

[root@kongd ~]# date "+%Y-%m-%d %H:%M:%S" 
2020-09-05 09:14:35

The date command to set the current time of the system to 8:30 on November 1, 2020 is as follows:

[root@kongd ~]# date -s "20201101 8:30:00" 或者[root@kongd ~]# date 
110108302020 
Sun Nov 1 08:30:00 CST 2020

2.4 timedatectl command

The timedatectl command is used to set the system time. The full English name is: "time date control". The syntax format is: timedatectl [OPTIONS...] COMMAND ...
Found that the computer time does not match the actual time? If the difference is only a few minutes, we can adjust it directly. But if the difference is a few hours, in addition to adjusting the
current time, it is also necessary to check the time zone. The parameters and functions of the timedatectl command:

parameter effect
stories Show status information
list-timezones List known time zones
set-timezone Set effective time zone
set-time Set system time

Check the system time and time zone:

[root@kongd ~]# timedatectl status 
							Local time: Sun 2020-09-06 19:51:22 CST 
					Universal time: Sun 2020-09-06 11:51:22 UTC 
					          RTC time: Sun 2020-09-06 19:51:21 
					        Time zone: Asia/Shanghai (CST, +0800) 
System clock synchronized: no
						NTP service: inactive
					RTC in local TZ: no

If the time zone you found is not Shanghai (Asia/Shanghai), you can set it manually:

[root@kongd ~]# timedatectl set-timezone Asia/Shanghai

If the time is still incorrect, we can manually modify the system date:

[root@kongd ~]# timedatectl set-time 2021-05-18

And if you want to modify the time, it is also very simple:

[root@kongd ~]# timedatectl set-time 9:30 
[root@kongd ~]# date 
Tue May 18 09:30:01 CST 2021

Guess you like

Origin blog.csdn.net/Nirvana92/article/details/127524596