First introduction to Linux (Part 2). My mother no longer has to worry about me finding the way to Linux.


Preface

"I will regularly share my study and work experience, and welcome everyone to leave messages and communicate so that we can learn and make progress together! Thank you for your support!"

Series of articles

First introduction to Linux (Part 1). My mother no longer has to worry about me finding the way to Linux.

First introduction to Linux (Part 2). My mother no longer has to worry about me finding the way to Linux.

First introduction to Linux (Part 2). My mother no longer has to worry about me finding the way to Linux.


1.man command (important):

Syntax: man [options] command

Function: Linux commands have many parameters. It is impossible for us to remember them all. We can get help by checking the online manual. The command to access the Linux man page is
man

-k 根据关键字搜索联机帮助
num 只在第num章节找
-a 将所有章节的都显示出来,比如 man printf 它缺省从第一章开始搜索,知道就停止,用a选项,当按下q退出,他会继续往后面搜索,直到所有章节都搜索完毕。
解释一下,面手册分为8章 
1 是普通的命令
2 是系统调用,如open,write之类的(通过这个,至少可以很方便的查到调用这个函数,需要加什么头文件) 
3 是库函数,如printf,fread4是特殊文件,也就是/dev下的各种设备文件
5 是指文件的格式,比如passwd, 就会说明这个文件中各个字段的含义
6 是给游戏留的,由各个游戏自己定义
7 是附件还有一些变量,比如向environ这种全局变量在这里就有说明
8 是系统管理用的命令,这些命令只能由root使用,如ifconfig 

For example:

Enterman -ls displays the following results:
You can see the user manual about ls listed. At this time, press Enter or the keyboard Turn up and down. Press ctrl+z to exit
Insert image description here
But this is not the real use of the man command
We can enter man mam To understand this command, you can find that it has a corresponding chapter number, and each chapter has a corresponding information type
Insert image description here
So the real usage of this command is to use it with a number, without a number, the default The query is the first
inputman 3 ls to view the library call (library function)
Insert image description here


2.cp command (important):

Syntax: cp [options] source file or directory target file or directory

Function: Copy files or directories

Common options:

-f 或 --force 强行复制文件或目录, 不论目的文件或目录是否已经存在
-i 或 --interactive 覆盖文件之前先询问用户
-r递归处理,将指定目录下的文件与子目录一并处理。若源文件或目录的形态,不属于目录或符号链接,则一律视为普通文件处理
-R 或 --recursive递归处理,将指定目录下的文件及子目录一并处理

For example:

Copy 123.txt to the a directory

Transportationll——cp 123.txt a——cd a——llShowing Result
Insert image description here

Similar to window operations:

Insert image description here
Note: Linux is the same as Windows. Files with the same name are not allowed to exist in the same directory.


3.mv

Syntax: cp [options] source file or directory target file or directory

Function:

  1. Depending on the type of the second parameter in the mv command (whether it is a target file or a target directory), the mv command renames the file or moves it to a new
    directory. .
  2. When the second parameter type is a file, the mv command completes the file renaming. At this time, there can only be one source file (it can also be the source directory name), which
    Renames the given source file or directory to the given destination file name.
  3. When the second parameter is an existing directory name, there can be multiple source files or directory parameters, and the mv command will move all the source files specified by each parameter to the target
    in the directory.

Common options:

-f :force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖
-i :若目标文件 (destination) 已经存在时,就会询问是否覆盖!

For example:

Rename the text file ''123.txt'' to ''321.txt''
Entermv 123.txt 321.txtto achieve the following results
Insert image description here

Similar to window operations:

Insert image description here
So how to implement the move function? It is very simple. Just change the original name to the path to be moved.
Move the text file "321.txt" to In directory a, operate as follows
Entermv 321.txt a——ll to achieve the following results
Insert image description here


4.nano

Syntax: nano [text file]

Function: Organizer in Linux

For example:

Edit text files through nano321.txt

Enternano 321.txt to reach the following interface. The following ^ corresponds to a command, which means ctrl key, such as ^ x meansctrl +xexit.
Insert image description here
So we can program in Linux. Create a Test.c file and open it with nano.
Insert image description here
Enter the basic c program and save it.
Save method (ctrl+x ->y->Enter)
Insert image description here
After saving, enter to install. . Enter The command has no effect and needs to be installed Ifgcc Test.cPress Enter, an a.out file will be generated. If you execute the file at this time, you can see the running results of the program
Insert image description here
nano
yum install -y nano


5.cat

Syntax: cat [options][file]

Function: View the contents of the target file

Common options:

-b 对非空输出行编号
-n 对输出的所有行编号
-s 不输出多行空行

For example:

Print the contents of the Test.c file

Inputcat Test.c displays the following content:
Insert image description here
You can also print backwards and write cat forward tac
Entertac Test.c to display the following content:
Insert image description here


5.more command

Syntax: more [options][file]

Function: more command, similar to cat

Common options:

-n 对输出的所有行编号
q 退出more 

For example:

The difference between more and cat:

cat will print all the content at once, no matter how big your text is, it will print all at once
more Print one screen at a time, stop printing when the screen is full, press the down key to proceed Print, let the user scroll down, and print line by line after filling the screen.

Currently, 10,000 lines of data are being printed: %3 below indicates the progress of printing. Press ctrl+z to exit printing.
Insert image description here


6.less directive (important)

Syntax: less [parameter] file

Function:

Less is similar to more, but with less you can browse the file at will, while more can only move forward, not backward, and less does not load the entire file before viewing.

Common options:

-i  忽略搜索时的大小写
-N  显示每行的行号
/字符串:向下搜索“字符串”的功能
?字符串:向上搜索“字符串”的功能
n:重复前一个搜索(与 / 或 ? 有关)
N:反向重复前一个搜索(与 / 或 ? 有关)
q:quit 

Can be used to view large text, recommended


7.head command

Head and tail are as easy to understand as their names. They are used to display a certain number of text blocks at the beginning or end. Head is used to display the beginning of the file to the standard output, while tail is used to read the file. end.

Syntax: head [parameter]… [file]…

Function: head is used to display the beginning of the file to the standard output. The default head command prints the first 10 lines of the corresponding file.

Options:

-n <行数> 显示的行数

For example:

Only show the first 5 lines
Enterhead -5 321.txt
Insert image description here


8.tail command

The tail command writes the file to the standard output starting from the specified point. Use the -f option of the tail command to conveniently check the changing log file. tail -f filename will display the last content of filename on the screen, and not only refresh , allowing you to see the latest file content.

Syntax: tail[required parameters][selected parameters][file]

Function: Used to display the content at the end of the specified file. When no file is specified, it will be processed as input information. Commonly used to view log files.

Options:

-f 循环读取
-n<行数> 显示行数

For example:

Only show the last 3 lines

Inputtail -3 321.txt
Insert image description here
So here comes the question, what should I do if I want to display rows 6000 to 6010?
inputhead -6010 321.txt |tail -11
Insert image description here

The command| is called a pipeline in Linux. It can be understood like this. First, the hend command displays lines 1-6010
Then tail gets the data displayed by head through | (pipeline) and runs it. The last 11 lines of 6010 are displayed, so that the 6000 lines are displayed. Line 6010

Expand

wc command, count text lines
inputwc -l 321.txt
Insert image description here


Conclusion

Thank you for reading my blog, I hope you can get some inspiration and help from it. If you enjoyed this blog, please share it with your friends and family, and please leave your comments and feedback. Your support is my motivation to continue sharing and creating. Thanks! Hope we can see each other again in a future blog. I wish you all the best and look forward to seeing you again!

Guess you like

Origin blog.csdn.net/2203_75397752/article/details/134601639