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 achieve redirection in linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about how linux can be redirected. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Linux redirection

First look at > and > >, their two functions are similar, they are output to a file, the only thing is that > will overwrite the original content of the file, and > > is appended after the original content.

Then there is the use of 1 >, 2 >, 1 > >, 2 > >, which is used when the correct output and error output need to be saved separately. For example, when executing a script. Use a simple python script to explain:

The script is as follows:

# coding: utf-8if _ _ name__ = ='_ _ main__': print 'Hello' int (' Hello')

The script first outputs "Hello", which is normal, and then converts "Hello" to int type, where an error is reported. Run directly:

$python test.py > txtTraceback (most recent call last): File "test.py", line 4, in int ('Hello') ValueError: invalid literal for int () with base 10:' Hello'$cat txtHello

You can see that the correct output is saved to the result.txt file, while the error message is output to the screen.

Do the following:

Python test.py 1 > right.txt 2 > wrong.txt$cat right.txtHello$cat wrong.txtTraceback (most recent call last): File "test.py", line 4, in int ('Hello') ValueError: invalid literal for int () with base 10:' Hello'

The correct output is saved to right.txt and the error output is saved to wrong.txt

1 > > and 2 > > and > > are similar, adding new content to the original content.

Thank you for reading! This is the end of the article on "how to redirect linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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

Development

Wechat

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

12
Report