Table of contents
1.2. Use the desktop terminal to access linux
1.3, remote connection to linux server
1.3.1, Xshell remote connection to linux
1.3.2. Control the server through remote software
Chapter 2 Executing commands in linux
Easy to use LINUX
1.1 The composition of linux
Linux kernel : The kernel is the core of the system, the core program that runs programs and manages hardware devices such as disks and printers.
File system : A method of organizing files effectively on storage devices such as disks. Linux can support a variety of currently used file systems, such as ext4, FAT, VFAT, ISO9960, NFS, SMB, etc.
shell : The shell is the user interface of the system, providing an interface for the user 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 the shell. The shell is the interface (graphics and characters) provided by the operating system to the user. It provides an interface for the user to interact with the kernel. When the user issues instructions (commands or mouse operations), these instructions are first sent to the shell, and the shell translates the user's instructions and sends them to the kernel, and then the kernel controls the work of the hardware. Then the kernel sends the working condition of the hardware to the shell, and the shell returns the working information and condition of the hardware.
Classification of shells :
GUI shell: KDE, GNOME
Character interface shell: bash, etc.
1.2 , use the desktop terminal to access linux
Terminal: Also known as terminal equipment, it is the most peripheral equipment in the computer network, mainly used for the input of user information and the output of processing results. In the activities overview, select the terminal from the dashboard
Virtual terminal: multiple terminals are virtualized on the same device (physical device), and they do not affect each other. These terminals are virtual terminals, and there are 6 by default. You can use ctrl + alt + f[1/2/3/4 /5/6] to switch.
Enter the command on the terminal window, the format of the command: main command option parameter (operation object)
(1) View the current linux distribution information
[root@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.2 (Ootpa)
(2) Check the kernel version
[root@localhost ~]# uname -r
4.18.0-193.el8.x86_64
The Linux kernel version number has gone through three different naming schemes:
Versions before 1.0-2.6: ABC
A --- major version number with major changes:
B --- Minor version number with some major changes
C --- refers to the revision number with minor revisions, C is the odd development version, and the even number is the stable version.
Version 2.6.0.0 ~ 2.6.39.4: ABCD
A and B --- are fixed to 2 and 6 in turn; C --- is the version of the kernel: 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 are no longer used to represent the stable version, and odd numbers are used to represent the development version.
Mainline --- mainline version (represents the version that the main force is currently working on or the development version)
Stabled --- stable version
Longterm --- Long term support version
EoL(End of Life) --- The old version of I that has stopped technical support,
(3) View the type of shell
Method 1: cat /etc/shells
[root@localhost ~]# cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
Method 2: chsh -l
[root@localhost ~]# chsh -l
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
(4) View the current default shell
[root@localhost ~]# echo $SHELL
/bin/bash
(5) shell prompt: # and $
For ordinary users, the default prompt of the Base shell is the dollar sign $;
For the super user (root user), the default prompt of the Base shell is the pound sign #.
Ordinary user login: [currently logged in user@hostname current working directory]$
Root user login: [root@host name current working directory]#
(6) Use commands to restart and shut down the Linux operating system
Reboot: reboot, shutdown -r now
[root@localhost ~]# reboot
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) View network card information and obtain IP address
Get the IP address:
[root@localhost ~]# dhclient
#If the prompt does not have this command, you need to install the package before using it, and you can use the nmcli command to get the address
[root@localhost ~]# nmcli con up ens160
Check the IP address:
[root@localhost ~]# ip a
#Note: The lo network card is a loopback network card, which is mainly used for local testing, and the ens160 is the network card for our remote connection.
1.3, remote connection to linux server
Ways to remotely connect to the Linux server: Classified by display type, it can be divided into two types: character interface and graphical interface. Character interface software includes SecureCRT, PUTTY, xshell, mobaxterm, etc.; graphical interface includes Xmanager, Xdmcp, and VNC software, etc.
1.3.1, Xshell remote connection to linux
(1) Double-click the xshell icon on the desktop to start the xshell program.
In this window, manually enter the IP address of the ssh root@linux host, enter the Enter key, and then enter your root user password in the pop-up password input prompt window, and you can log in successfully as the root user.
In this window, manually enter the ssh common user name@linux host IP address, enter the Enter key, and then enter your common user password in the pop-up password input prompt window, and you can log in successfully as a normal user.
1.3.2. Control the server through remote software
The remote connection is successful as shown in the figure below:
(1) Switch to the ordinary user you added when installing the system
[root@localhost ~]# su - rhcsa
[rhcsa@localhost ~]$
#输入exit退出
[rhcsa@localhost ~]$ exit
Logout
[root@localhost ~]#
#View currently logged in users
[root@localhost ~]# whoami
Root
(2) To modify the host name, you need to re-connect remotely to take effect
[root@localhost ~]# hostname server
#临时修改,重启linux系统之后失效
[root@localhost ~]# hostnamectl set-hostname server
#永久生效,修改的是文件内容。重启linux系统后依旧生效
#View the hostname configuration file
[root@localhost ~]# cat /etc/hostname
Server
(3) View the current working directory: pwd
#root用户
[root@localhost ~]# pwd
/root
#普通用户
[root@localhost ~]#su - rhcsa
[rhcsa@localhost ~]$ pwd
/home/rhcsa
Note: The directory path representation of windows and linux systems is different
(4) Change the current working directory, that is, switch directory
Absolute paths (paths starting with /)
Relative paths (paths that do not start with /) [
root@localhost ~]# cd /
[root@localhost ~]# cd -
/root
注:该操作会让你回到上一次切换的目录下
[root@localhost ~]#
[root@localhost /]# cd /home
[root@localhost home]# cd /home/rhcsa
[root@localhost rhcsa]# cd ~
注:~代表当前用户的家目录,当前用户为root,则代表为root用户的家目录
[root@localhost ~]# cd . . 注: . . 代表当前工作目录的上一级目录
[root@localhost ~]# cd . 注:.代表当前工作目录
(5) Modify password
[root@localhost ~]# passwd
[root@localhost ~]# passwd rhcsa
[root@localhost ~]# passwd -d rhcsa
#删除rhcsa用户的密码
Analysis: The similarities and differences between ordinary users and root users modifying passwords
Ordinary users: 1. Need to enter the original password
2. Username cannot be specified when changing password
3. Need to be longer than 8 characters and cannot be systematized
1.4 reset root password
Method 1: rd.break
The first step is to restart the system and press the e key on the interface shown in the figure below
The second step is to find the linux line, enter rd.break after the space at the end
then press ctrl+x
The third step to view, optional step
Here sysroot is mounted in read-only form, so it should be mounted in a readable and writable manner
The fourth step is to mount /sysroot in read-write mode
The fifth step is to change the password
Enter the /sysroot subsystem and change the password
The sixth step is to force reset the context of the file system
The seventh step is to exit, exit
Execute exit again, reset the file system context, there will be a percentage
Method 2: init method
1. Start the system, and when the GRUB2 startup screen is displayed, press the e key to enter the edit mode.
Add the following content at the end of the parameter line where linux is located:
(1) Change ro to rw
(2) Add init=/bin/sh at the end
2. Press ctrl+x to boot into the shell.
3. Run passwd, and follow the prompts to change the root password or use the following command to change the password:
Echo"pwd" | passwd -- stdin root
4. If the system has enabled selinux before, the following command must be run, otherwise the system will not start normally: touch /.autorelabel
5. Run the command exec /sbin/init to start normally, or use the command exec /sbin/reboot to restart
Chapter 2 Executing commands in linux
2.1 Command format
Command format: main command option parameter (operation object)
Commands fall into two categories:
Built-in commands: commands that come with the shell program
External command: There is an independent executable program file, and the file name is the command name
Option : specify the running characteristics of the command, specify which function code in the command to run.
Short options: For example: -l, -d, if the same command uses multiple short options at the same time, most of them can be combined. (Note: some commands have no options)
Long options: eg: --help, --human-readable
Parameters : the object of the command, that is, what the command takes effect on. The parameters of different commands are different, some options can take parameters, some options can not take parameters, some commands can take multiple parameters at the same time, and multiple parameters are separated by blank characters
Terminate the current command :
Press ctrl+c to interrupt the command being executed
Two complements :
Completion command: After entering the first few characters of the command keyword, press the Tab key to realize the automatic completion of the command
Complete the file name and directory name: After entering the first few characters of the file, press the Tab key to complete automatically
[root@localhost ~]# passwd -d rhcsa
[root@localhost ~]# cat /etc/redhat-release
[root@localhost ~]# uname -r
4.18.0-193.el8.x86_64
Note:
Command name: what you want to do
Option: how do you do it
Parameters: who is the object you want to operate
Options and parameters: combined with each other
After executing a command?
? : Represents the status code returned after the command was executed last time
0: successful execution
127:command not found
2.2 View command help
1. View bash internal command help
[root@localhost ~]# help 内部命令
2. Use the command --help option to view help
[root@localhost ~]# cat --help
3. Use the help command --- man command name
[root@localhost ~]# man 命令
Commonly used keys and their functions in the man command
button |
effect |
space bar |
turn down one page |
PaGe down |
turn down one page |
PaGe up |
turn up a page |
home |
Go directly to the home page |
end |
Go directly to the last page |
/ |
Search for a keyword from top to bottom, such as "/linux" |
? |
Search for a keyword from bottom to top, such as "?linux" |
n |
Locate to the next searched keyword |
N |
Target the last searched keyword |
q |
exit help document |