One of the common Linux commands that developers need to be familiar with: the redirection Operator

Source: Internet
Author: User
Tags svn update

I remember sorting out a list of commonly used Linux commands, but I cannot find a list of common Linux commands. I can only make one more list;

As a developer, we may do some things when logging on to Linux: SVN update code, publishing applications, transferring files between Linux servers, and directly searching and modifying files on the server; the following lists some common commands. Of course, they are only the most common usage of each command. If you want to view all the parameters and functions, you can turn to help or man;

The most common CD ll LS ~ . Cat RM mkdir cp mv du DF will not be introduced much;

Su: Switch between users. Pay attention to the difference between Su admin and Su-Admin. The former will not reload the admin user's environment variables, while the latter will reload;

Tail: View the information at the end of the file. Generally, this parameter is used with the-F-nxx parameter to display the last XX lines of the file and follows the file. That is, if the file changes, the changed part is automatically displayed;

Ifconfig: Used to view the IP address of the local machine, which is located in the/sbin/directory and is not in the environment variable by default. Advanced functions include changing the IP address;

W: View logon users on the current server, their source IP addresses, and logon time;

Uptime: View the current system running status, such as the running time, average load in the last 1, 5, and 15 minutes;

Top: Displays the running status of the current system dynamically, similar to the Windows Task Manager;

Kill killall: Force close a process, which is generally used in conjunction with-9, means to immediately kill rather than waiting for the application to automatically close;

Diff: Compare the similarities and differences between the two files. The displayed information is the differences between the two files, specific to a specific line;

Wget curl: Capture the page information of the URL. The former generates a file, and the latter is printed directly on the console;

Tracert: Tracking the routing of an IP address, which is useful in solving some network problems;

Netstat: View the port information occupied by the current system. It is generally used together with | grep to check whether a specific port is occupied;

Nohup &: Specifies that the application is executed in the background. The former indicates that the application runs normally when the user exits securecrt, while the latter indicates that the application is valid only when the user does not exit securecrt, and the process becomes invalid after the user exits; this is useful when we execute a script that takes a long time;

>>><: Input information to the target, or read the input information from the target;> indicates Direct Overwrite, and> indicates append;

 

The following describes the expanded redirection operators. For example, we often see such statements:Mysh> mylog.txt 2> & 1What does that mean?

The redirection operator can be used to redirect command input and output data streams from the default location to other locations. The input or output data stream locations are called handles. There are three common handles. Of course, the handles can be expanded on their own, generally, operating systems provide similar functions:

 

Handle Handle Code Handle description
Stdin 0 Keyboard Input
Stdout 1 Output Information to the prompt window
Stderr 2 Output Error information to the prompt window

 

The default <redirect input operator is 0, and the default> redirect output operator is 1. After you type the <or> operator, you must specify the data read/write location, which can be a file name or another existing handle.
To specify the redirection to an existing handle, use the and & character followed by the handle number (that is, & handle number) to be redirected ).
For example, the following command can redirect handle 2 (stderr) to handle 1 (stdout): 2> & 1
The following table lists the operators that can be used to redirect input and output data streams:

 

Redirection Operator Function Description
> Write command output to a file or device instead of a command prompt or handle
< Reads command input from a file instead of a keyboard or handle
> Add command output to the end of the file without deleting the existing information in the file
> & Write the output of one handle to the input of another handle.
<& Reads input from one handle and writes it to another handle output.
| Reads the output from one command and writes it to the input of another command. It is also called a pipeline operator.

 

Now let's look back at the above statement mysh> mylog.txt 2> & 1 to understand:

> Mylog.txtis intended to redirect the standard output to mylog.txt, which is equivalent to mysh 1> mylog.txt;

2> & 1 running;

The redirection function is very powerful. If you are interested, you can try different combinations to see what results will happen when the front and back positions change?

In some cases, we may not want to record any standard output or error output. You can use mysh> null 2> null or mysh>/dev/null 2>/dev/NULL;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.