Linux basic instructions (2)

 Today we continue to learn our instructions about Linux. There are many more instructions today than last time. Let’s start our study.

man manual

Let’s look at the title first. The first thing we think of about the manual is the search function of the manual. We all know that when we were in elementary school, if we encountered a word we didn’t know, we would read the pinyin of the word by consulting the dictionary. Of course We will also directly ask the teacher how to read. At this time, the teacher is like this man.

Our Linux also has its own manual, which we can use to check our daily instructions and some functions of the C language. Let's take a look together.

When we run man ls we will enter the manual.

We can look up the meaning of ls. When we want to exit, we only need to click Q on our keyboard to exit our manual. However, some people don't know what man is, so we can also look at it this way.

man man command to see our manual.

We can see these. What we will commonly use in the future is the 1 2 3 manual. When we use it, we point it in order. For example, we also have printf under Linux. Let’s take a look.

We can also use man printf.

We will come back to explain this later, but let’s take a look now.

man manual installation 

Some cloud servers do not have man manuals, we only need to enter the command  yum install -y man-pages

We must also switch to root before we can install it. Ordinary users cannot perform this command. Of course, we can also perform su privilege escalation on the command later. I will talk about it later. Here, you only need to switch to the root super user when installing. Just install it.

You can also try it after we install it.

  

I found that the man manual can also be used. The query is printf in C language. Why can the man manual also query C language? Because in fact, many of our Linux are written in C language.

man [options] command 

-k Search online help based on keywords
num present day num chapter
-a Display all chapters, such as man printf It defaults to the first Start searching for a chapter, stop when you know it, use a option, when press
Next q Exit, he will continue to search until all chapters are searched
So in the future, if there is anyone you don’t know under Linux, you can also query it.
Copy files and directories
Sometimes if we want to copy a file under Windows, we usually use ctrl plus C and V to copy it to the path we want. Then our Linux also has such an instruction, which is our cp (not cpdd) .
cp command
When talking about the cp command, we need an existing file, so we have to create a file, just use the touch code.c we talked about last time.
file, and then we nano write something in it to take a look.

We have also written this content, and then cat can print out the contents of our file. Let's first talk about how to use our cat command.

cat

cat [ choice ][ text ]
-b Non-empty output line number
-n Number all lines of output
-s Do not output multiple blank lines
This is how we use cat. In fact, everyone here only needs to understand that we are printing the content of the file to our monitor, so it means to view the content of the file and display it on the monitor.
Then we first create a directory of 111. If we want to move this file to the path of 111, we can just cp code.c 111. We are operating on files here, not directories.
Let's see the effect.

So the usage of cp is

cp  src dst

We said above that cp src dst can only operate on files. If we not only want to operate on files, we also have to operate on directories. We all know that to operate on directories, we can write cp -rf. The r here means recursive copy. , f is mandatory. Don’t ask me whether I want to copy it, just copy it. I’ll give it a try.

We also saw that it was copied successfully.

The cp command is used to copy files or directories. If two or more files or directories are specified at the same time, and the final destination is an existing directory, it will copy All files or directories specified previously are copied to this directory. If multiple files or directories are specified at the same time, and the final destination is not an existing directory, an error message will appear

Common selection :

-f or --force  Forcibly copy a file or directory, regardless of whether the destination file or directory is Already exists
-i or --interactive Previously read the cover text
-r Recursive processing, processing files and subdirectories in the specified directory together. If the form of the source file or directory does not belong to a directory or symbolic link, it will be treated as an ordinary file.
-R or --recursive recursively process the files and subdirectories in the specified directory Processed together
There is a copy command, so there must be a cut function. Let's learn about it.
mv command
When we are under Windows, if we want to cut a file, we will click this ✂

Then we can use the mv command to cut files under Linux, let's take a look.

The above operation is to move our original directory a under 111 to lesson2, so the mv command is the following usage method.

mv [options] src dst 

Of course, our mv can also be renamed, we can also take a look.

 The following instructions are how to view the contents of the file.

We first need to create a large file. You can write the following code to create it. You can just copy and paste this code. We will talk about it later. Now you only need to understand that our code is to create 10,000 hellos. That's it.

cnt=1;while [ $cnt -le 10000 ]; do echo "Hello! $cnt"; let cnt++; done > large.txt

At this time we have a file called large.txt. Our current problem is how to check it. The cat we learned before will not work here because it can only print a full page, so it does not work. We will introduce a few new instructions here.

One is more

moer command

When we directly add more to our file, a whole page of hello is printed out, but we can only keep pressing Enter to query, and we can only query all the way down, not back, in case we use All of a sudden, if you press Enter too many times, you have to start over again, so this command is not very good. We also have more options, such as adding - number of lines to get to that line. Let’s take a look.

Click q to exit

This is the command that was just executed.

If there is more, there is less. Let’s take a look at less.

less command 

The less  tool is also a tool for paging display of files or other output. It should be said that linux An orthodox tool for viewing file content, extremely functional
Its powerful.
less  的用法比起  more  更加的有弹性。在  more  的时候,我们并没有办法向前面翻, 只能往后面看
但若使用了  less  时,就可以使用  [pageup][pagedown]  等按键的功能来往前往后翻看文件,更容易用
来查看一个文件的内容!
除此之外,在  less  里头可以拥有更多的搜索功能,不止可以向下搜,也可以向上搜
 
 less [参数] 文件

less more 类似,但使用 less 可以随意浏览文件,而 more 仅能向前移动,却不能向后移动,而且 less 在查看之前 ,不会加载整个文件。我们也可以往回翻动,加上上下键位就可以了。
选项
-i   忽略搜索时的大小写
-N   显示每行的行号
/ 字符串:向下搜索 字符串 的功能
? 字符串:向上搜索 字符串 的功能
n :重复前一个搜索(与  /   ?  有关)
N :反向重复前一个搜索(与  /   ?  有关)
q:quit

head指令 && tail指令

head

head   tail  就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块, head  用来显示档案的 开头至标准输出中,而 tail  想当然尔就是看档案的结尾。
head [ 参数 ]... [ 文件]
head  用来显示档案的开头至标准输出中,默认 head 命令打印其相应文件的开头 10 行。

tail指令

tail  命令从指定点开始将文件写到标准输出 . 使用 tail 命令的 -f 选项可以方便的查阅正在改变的日志文件 ,tail - f filename会把 filename 里最尾部的内容显示在屏幕上 , 并且不但刷新 , 使你看到最新的文件内容 .
tail[ 必要参数 ][ 选择参数 ][ 文件
用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理。常用查看日志文件。

今天的分享就到这里我们下次再见。

Guess you like

Origin blog.csdn.net/2301_76895050/article/details/134927579