Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the Linux redirection method

Shulou Source: shulou.com Published: 2022-06-01 12:31:18 09月18日 Update

This article mainly explains "how to use the Linux redirection method". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the Linux redirection method".

Data flow in Linux

When it comes to Linux redirection, we have to mention the following three types of data flows:

The input information is read from the stdin (standard input, usually keyboard or mouse).

The output information is output to stdout (standard output, a text file, or data stream).

The error message is output to stderr.

Knowing the existence of these data streams, you can better control the flow of data when you use Shell.

In Linux systems, standard input, standard output, and standard error all exist as files. You can see them in the / dev directory:

$ls / dev/std* / dev/stderr / dev/stdin / dev/stdout

Redirect output

In Linux systems, the > character is used to indicate redirected output. For example, redirect the output of the ls command to a file:

$ls > list.txt

After executing the above command, the output of the ls command is not displayed on the screen because the output has been redirected to the list.txt file.

In addition, redirection has many uses, it can also be used to copy the contents of files, and not limited to copying text files, binary files can also be copied:

$cat image.png > picture.png

If you want to copy the contents of one file to the end of another, you just need to replace the > character with the > > string, like this:

$cat lxlinux > > alvin

Redirect input

In contrast to redirected output, redirected input uses the

Tags: File output input information data standard command character error string method content data flow text parameter system learning function just screen Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Technology Shulou Tech Info Shulou Information macOS