Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize redirection in Linux

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to achieve redirection in Linux, the content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

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 > > alvi

Redirect input

In contrast to redirected output, redirected input uses the

< 字符。 输入重定向可以将输入信息重定向至命令中作为参数使用。该功能可能比较少用,但是,当命令需要一个参数列表时,而这些参数都存在一个文件中,然后你想快速地将它们从文件中复制粘贴到终端,这时这个功能就能派上用场了。 例如,package.list 里记录了你需要安装的包的列表,而你想要快速地安装所有的包,只需执行以下这一条命令,就能一次性安装 package.list 里的所有包: $ sudo dnf install $( lxlinux.net >

EOF

The expected output should look like this:

Alvin lxlinux.net

Here-doc is a common technique used by Bash scripting writers to dump multiple lines of text to a file or screen.

Here-string is similar to Here-doc, but it has only one string, or several strings enclosed in quotation marks:

$cat

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report