What is redirection in linux

WBOY
Release: 2022-03-16 15:25:09
Original
5859 people have browsed it

In Linux, redirection is to redirect the data information originally to be output to a specific file, that is, to change the default execution method of the original system command; redirection is generally done through the command This is achieved by inserting specific symbols between them. The syntax example is "command1 > file1".

What is redirection in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is redirection in Linux

Linux redirection refers to modifying some of the original default things and changing the default execution method of the original system command. For example, simply I don’t want to see it in If you want the output of the monitor to be output to a certain file, you can do this through Linux redirection.

1. What exactly is redirection in Linux?

Redirection in Linux is to redirect the data information originally output to the screen to a specific file, or to a black hole (/dev/null).

1.2 What is the use of redirection?

1. When the program executes and outputs a lot of information, it needs to be saved and viewed in paging.

2. Programs executed in the background generally have output, and we do not want its output to interfere with the terminal.

3. Perform scheduled backup tasks and hope that the backup results will be retained.

4. When creating a user repeatedly, some error messages will be prompted, and the information can be discarded directly.

5, when you want to save the error log and correct log to different files.

1.3 Standard input and output

When a process operates a file:

1, first of all, the process cannot directly access the hardware and needs to use the kernel To access file

2, the kernel needs to use a file descriptor to access the file.

Summary: Process --- access ---> file name through ---> file descriptor (non-negative integer); the process uses file descriptors to manage the correspondence between open files.

Step 1: Run tail -f /etc/passwd

Part 2: Pass file descriptor 3--->/etc/passwd-->inode--> ;block

Step 3: Correct output--->By default, through file descriptor 1--->Current terminal 1>(Change the output location, file, black hole)

Step 4: Error output--->By default, through file descriptor 2---》Current terminal 2>(Error output)

Usually a program will open at least three criteria when accessing a file Files are standard input, standard output, and error output.

The process will get data from the standard input, print normal output to the screen terminal, and print error output information to the screen terminal.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What is redirection in linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template