How should Linux output to a file after executing some commands or accessing some website resources?

Zimu u 2022-06-24 05:44:44 阅读数:987


Share one today linux Tips , It can help you in your daily operation and maintenance , More time saving , More labor saving !

We often Linux There are some errors after executing some commands on or accessing some website resources 、 Overtime , But I want to count some errors in another file , How to output to a file ?

Today we need to use linux in bash The redirection function of

The example command is as follows :cmd 2>>file

This command means to append the error of standard output to file In file ,cmd For any command .

The specific usage examples are as follows :

1、 I curl You can see that it is returned http 301 Status code , Permanent redirection , The description can be accessed normally , There is no mistake

2、 If I curl Yes., It will output an error , Prompt: the domain name cannot be resolved , If the request command is executed in the application layer business program in this way , It cannot be directly output to the terminal for us to check , And it is called in the application , The links involved , There are a lot of error messages , If we need to get one alone curl To reproduce and record every error in a file , It's not very good to go to the terminal

3、 And then we use bash The redirection function of , Append standard error output to a specified file , You can see me curl 了 5 Time , No, there are mistakes , And all these 5 The error information of times is recorded in the file specified by me .

copyright:author[Zimu u],Please bring the original link to reprint, thank you.