The importance of learning Linux for a programmer is self-evident. Front-end development has Linuxrelatively few exposure opportunities compared to back-end development, so it is often easy to ignore it. But learning it well is one of the must-haves for programmers.
If this article is helpful to you, please click 👍.
The author uses Alibaba Cloud server ECS (the cheapest one) CentOS 7.7 64-bit. Of course, you can also install a virtual machine on your own computer, and then install CentOS the system in the virtual machine (this is completely free). As for its installation tutorial, you can go to Google to search, there are many related tutorials.
Linux Basics
operating system
Operating system for Operating System short OS , is a part of software, it is the first layer of software on the basis of hardware, and is a bridge between hardware and other software.
The operating system controls the operation of other programs, manages system resources, provides the most basic computing functions, such as managing and configuring memory, determining the priority of supply and demand of system resources, etc., and also provides some basic service programs.
what is linux
Difference Between Linux System Kernel and Linux Distribution
Linux The system kernel refers to the system core Linus Torvalds program that is responsible for maintenance and provides hardware abstraction layer, hard disk and file system control and multitasking functions.
Linux A distribution system is what we often call an Linux operating system, that is, Linux a collection of products consisting of the kernel and various commonly used software.
Summary: It really Linux refers to the system kernel, and what we often say Linux refers to "a complete operating system with some basic software included in the distribution".
Linux vs Windows
stable and efficient;
free (or a small fee);
Fewer vulnerabilities and quick fixes;
Multi-tasking and multi-user;
More secure user and file permission policies;
Embedded systems suitable for small kernel programs;
Relatively low resource consumption.
Types of Linux systems
Red Hat Enterprise Edition Linux : RHEL is the most widely used Linux system in the world. It is extremely performant and stable, and is the (paid) system used in many build environments.
Fedora : The desktop version of the system suite released by Red Hat, users can experience the latest technologies or tools for free. These technologies or tools will be added to the RHEL system when they are mature, so Fedora they also become RHEL the experimental version of the system.
CentOS : By RHEL recompiling the system and releasing it to users for free Linux , it has a wide range of users.
Deepin : Released in China, integrating and configuring excellent open source products.
Debian : Strong stability and security, provides free basic support, and has a high degree of recognition and usage abroad.
Ubuntu : is an operating system derived from Debian , and has strong compatibility with new hardware. Ubuntu Both Fedora are excellent Linux desktop systems and Ubuntu can also be used in the server world.
Terminal connection to Alibaba Cloud server
By executing the ssh [email protected] command, and then entering the server connection password, you can successfully log in to the remote server. From now on we can operate the remote server on the local computer.
This black panel is the terminal Shell (command line environment).
ssh root@xxx This is a command that must be Shell executed in .
Shell
Shell The original meaning of this word is "shell", which kernelcorresponds to (kernel), and is a metaphor for the layer outside the kernel, that is, the dialog interface for the user to interact with the kernel.
Shell is a program that provides an environment for dialogue with the user. This environment has only one command prompt, which allows users to input commands from the keyboard, so it is also called the command line environment ( command line interface , abbreviated as CLI ). Shell Receive the command input by the user, send the command to the operating system for execution, and return the result to the user.
Shell is a command interpreter that interprets commands entered by the user. It supports syntaxes such as variables, conditional judgments, and loop operations, so users can use Shell commands to write various small programs, also known as Shell scripts. These scripts are Shell executed through interpretation, not through compilation.
Shell Is a toolbox that provides a variety of small tools for users to easily use the functions of the operating system.
Kind of Shell
Shell There are many kinds of programs, as long as they can provide users with a command-line environment, they can be regarded as programs Shell .
Historically, the main ones Shell are:
Bourne Shell (sh)
Bourne Again shell (bash)
C Shell (csh)
TENEX C Shell (tcsh)
Korn shell (ksh)
Z Shell (zsh)
Friendly Interactive Shell (fish)
Which Bash is currently the most commonly used Shell . MacOS The default in Shell is Bash .
echo $SHELL You can view what is currently in use by executing the command Shell . You can also view all kinds of cat /etc/shells current system installations .Shell
Order
command line prompt
After entering the command line environment, the user will see Shell the prompt. The prompt is often a string of prefixes and ends with a dollar sign $ , after which the user can enter various commands.
Execute a simple command pwd :
[root@iZm5e8dsxce9ufaic7hi3uZ ~]# pwd /root 复制代码
Command parsing:
root: indicates the user name;
iZm5e8dsxce9ufaic7hi3uZ: indicates the host name;
~: Indicates that the current directory is the home directory, and the root user's home directory is the home directory of ordinary/root users ;/home
#: Indicates the permissions you have ( root for users, for # ordinary users $ ).
Execute the whoami command to view the current user name;
Execute the hostname command to view the current host name;
About how to create, switch, and delete users, users and permissions will be explained in detail later. Here, users will be used root for demonstration.
[Remarks] root is a super user and has all the permissions of the operating system.
Before starting to learn the Linux command, there are some shortcuts that must be mastered in advance, and it will be used throughout the Linux life.
Use the up and down arrow keys ↑ ↓ to recall the commands executed in the past Linux ;
Commands or parameters can be completed with Tab keys only by entering the first few digits;
Ctrl + R : used to find the used command (the history command is used to list all the previously used commands, and then enter the ! command plus the number ( !2 ) to directly execute the historical command);
Ctrl + L: clear the screen and move the current line to the top of the page;
Ctrl + C: Abort the currently executing command;
Ctrl + U: Cut from the cursor position to the beginning of the line;
Ctrl + K: Cut from the cursor position to the end of the line;
Ctrl + W: cut a word to the left of the cursor;
Ctrl + Y: Paste Ctrl + U | K | Y the cut command;
Ctrl + A: the cursor jumps to the beginning of the command line;
Ctrl + E: the cursor jumps to the end of the command line;
Ctrl + D: close the Shell session;
files and directories
organization of documents
view path
pwd
Display the path of the current directory
which
Check the path of the executable file of the Linux command. Each command actually corresponds to an executable program. When you enter a command in the terminal and press Enter, the corresponding program is executed. The program which corresponding to the command itself also exists in Linux middle.
In general, a command is an executable program.
Browse and switch directories
ls
List files and directories, it is one of Linux the most commonly used commands.
【Common parameters】
-a Show all files and directories including hidden ones
-l show detailed list
-h suitable for human reading
-t Sort by file last modified time
-i Display the file inode ( inode is the identification of the file content)
WeChat search public number: Architect Guide, Reply: Architects receive materials.
cd
cd It is an English change directory abbreviation, which means to switch directories.
cd / --> 跳转到根目录 cd ~ --> 跳转到家目录 cd .. --> 跳转到上级目录 cd ./home --> 跳转到当前目录的home目录下 cd /home/lion --> 跳转到根目录下的home目录下的lion目录 cd --> 不添加任何参数,也是回到家目录 复制代码
[Note] Enter cd /ho + single tab key will automatically complete the path + double tab key will list all possible directories.
du
List directory size information.
【Common parameters】
-h suitable for human reading;
-a At the same time, the size information of the files in the directory is listed;
-s Only the total size is displayed, no specific information is displayed.
Browse and create files
cat
Displays all the contents of the file at once, which is more suitable for viewing small files.
cat cloud-init.log 复制代码
【Common parameters】
-n Display line numbers.
less
Display file contents in pagination, which is more suitable for viewing large files.
less cloud-init.log 复制代码
【Quick operation】
Spacebar: advance one page (one screen);
b key: go back one page;
Enter key: move forward one line;
y key: go back one line;
Up and down keys: go back or forward one line;
d key: forward half a page;
u key: go back half a page;
q key: stop reading the file, abort less the command;
= key: display the content of the current page is the line to which line in the file and some other detailed information about the content of this page;
h key: display the help document;
/ Key: After entering the search mode, press the n key to jump to a matching item, and N press the key to jump to the previous matching item. At the same time, you can also enter a regular expression to match.
head
Display the first few lines of the file (default is 10 lines)
输入 man + 数字 + 命令/函数,可以查到相关的命令和函数,若不加数字, man 默认从数字较小的手册中寻找相关命令和函数
man 3 rand --> 表示在手册的第三部分查找 rand 函数man ls --> 查找 ls 用法手册复制代码
man 手册核心区域解析:(以 man pwd 为例)
NAME # 命令名称和简单描述 pwd -- return working directory nameSYNOPSIS # 使用此命令的所有方法 pwd [-L | -P]DESCRIPTION # 包括所有参数以及用法 The pwd utility writes the absolute pathname of the current working directory to the standard output. Some shells may provide a builtin pwd command which is similar or identical to this utility. Consult the builtin(1) manual page. The options are as follows: -L Display the logical current working directory. -P Display the physical current working directory (all symbolic links resolved). If no options are specified, the -L option is assumed.SEE ALSO # 扩展阅读相关命令 builtin(1), cd(1), csh(1), sh(1), getcwd(3)复制代码
help
man 命令像新华词典一样可以查询到命令或函数的详细信息,但其实我们还有更加快捷的方式去查询, command --help 或 command -h ,它没有 man 命令显示的那么详细,但是它更加易于阅读。
lo 表示本地回环( Local Loopback 的缩写,对应一个虚拟网卡)可以看到它的 ip 地址是 127.0.0.1 。每台电脑都应该有这个接口,因为它对应着“连向自己的链接”。这也是被称之为“本地回环”的原因。所有经由这个接口发送的东西都会回到你自己的电脑。看起来好像并没有什么用,但有时为了某些缘故,我们需要连接自己。例如用来测试一个网络程序,但又不想让局域网或外网的用户查看,只能在此台主机上运行和查看所有的网络接口。例如在我们启动一个前端工程时,在浏览器输入 127.0.0.1:3000 启动项目就能查看到自己的 web 网站,并且它只有你能看到。
wlan0 表示无线局域网(上面案例并未展示)。
host
ip 地址和主机名的互相转换。
软件安装
yum install bind-utils复制代码
基础用法
[root@lion ~]# host github.combaidu.com has address 13.229.188.59 [root@lion ~]# host 13.229.188.5959.188.229.13.in-addr.arpa domain name pointer ec2-13-229-188-59.ap-southeast-1.compute.amazonaws.com.复制代码
Vim 有一个特别便捷的功能那就是分屏,可以同时打开好几个文件,分屏之后,屏幕每一块被称为一个 viewport ,表示“视口”。
横向分屏 :sp 文件名
垂直分屏 :vsp 文件名
分屏模式下的快捷键
Ctrl + w 再加 Ctrl + w ,表示从一个 viewport 移动光标到另外一个 viewport ;
Ctrl + w 再加 “方向键”,就可以移动到这个方向所处的下一个视口了;
Ctrl + w 再加 + 号,表示扩大当前视口;
Ctrl + w 再加 - 号,表示缩小当前视口;
Ctrl + w 再加 = 号,表示平均当前视口;
Ctrl + w 再加 r 键,会反向调换视口位置;
Ctrl + w 再加 q 键,会关闭当前视口;
Ctrl + w 再加 o 键,会关闭除当前视口以外的所有视口;
运行外部命令 :!
在 Vim 中可以运行一些终端命令,只要先输入 :! ,然后接命令名称。
例如:
:!ls # 在Vim中打开的文件所在的目录运行ls命令 复制代码
可视模式
前面只讲了 Vim 的三种模式,其实还有一种模式叫做可视模式。
进入它的三种方式(都是从交互模式开始):
v 字符可视模式,进入后配合方向键选中字符后,然后再按 d 键可以删除选中。
V 行可视模式,进入后光标所在行默认被选中,然后再按 d 键可以删除所在行。
Ctrl + v 块可视模式,它是可视模式最有用的功能了,配合 d 和 I 键可以实现删除选中的内容和插入内容。
同时选中多行,并在选中行头部插入内容的具体操作步骤:
1. ctrl + v 进入块可视模式 2. 使用方向键进行选中(上下左右)假设选中5行 3. 输入 I 键进行多行同时插入操作 4. 插入完成后连续按两下 esc 键,实现多行同时插入相同字符 复制代码
进入可视模式之后的操作键:
d 键,表示删除选中;
I 键,表示在选中之前插入;
u 键,表示选中变为小写;
U 键,表示选中变为大写;
Vim configuration
option parameter
After Vim being started, you can run some commands to activate some option parameters, but the configuration of these option parameters Vim will be forgotten when you exit, such as the activation line number explained earlier. cd ~ If you want the configuration you are in to be permanent, you need to create a Vim configuration file in the home directory ( ) .vimrc .
.vimrc
set number " 显示行号 syntax on " 激活语法高亮 set showcmd " 实时看到输入的命令 set ignorecase " 搜索时不区分大小写 set mouse=a " 激活鼠标,用鼠标选中时相当于进入可视模式 复制代码
VimVim The configuration is very rich, we can make it our own through personalized configuration IDE and so on. You github can also search for some powerful Vim configuration files on .
Summarize
I believe that through the study of this article, you should Linux have a more comprehensive understanding.