当前位置:网站首页>10. Standard i/o redirection and pipeline
10. Standard i/o redirection and pipeline
2022-06-28 23:19:00 【51CTO】
Standard input and output
linux There are three kinds of I/O equipment
The standard input stdin -0 Accept input from the terminal by default
standard output stdout -1 Default output to terminal window
The standard error stderr -2 Default output to terminal window
I/O Redirect redirect
I/O Redirect : The default input , Output or error corresponding to device change , Point to a new goal
Standard output and error redirection
stdout and stderr Can be redirected to a specified file , Instead of the default current terminal ; Format : command The operator file name
1> or > hold stdout Redirect to file
2> hold stderr Redirect to file
&> Redirect all output to a file
If the above file already exists , The contents of the file will be overwritten
set -c It is forbidden to overlay existing files with content , But the best , utilize >| You can still force override
set +c Allow to override , default setting
Use >> You can add content to the original content (>> 2>> &>>)

Standard output and error output to different locations


Combine standard output and error input to redirect to the same data stream ( have access to &>> '1>file 2>&1')



Merge multiple program outputs (cmd1;cmd2) perhaps { cmd1;cmd2;...;} Merging multiple programs stdout {} A semicolon and... Are required at the end of the command cmd1 You need a space in front





Clear large File command ( The previous article explained )
cat /dev/null >/data/file.log
Redirect separately

Discard the output file (\dev\null Empty device file )

Standard input redirection
Import from a file stdin, Replace the input device of the current terminal , Use < To redirect standard input , Some commands can accept... Imported from a file stdin

tr command ( Convert characters and delete characters )
tr [option] .. set1 [set2]
Options
-d --delete: Delete all characters that belong to the first character set

-s --squeeze-repeats: The continuous repeated characters are represented by a single character , That is to say, to remove the weight ( notes : It needs to be continuous , Discontinuities do not )

-t --truncate-setl: Convert the character corresponding to the first character set to the character corresponding to the second character set

-c -C --complent: Take the complement of the character set




Standard input redirection
You can use < Redirect
Single line redirection ctrl+d The input can be terminated




Multiline redirection
Use "<< Stop words ” The command directs multiple lines from the keyboard to stdin, All text before the position of the terminator is known is sent to stdin; The terminator may be one or more occurrences such as !,@,$,EOF Wait for EOF More commonly used



The Conduit
The Conduit ( Use | Express ,) Can be used to connect multiple commands
Format command 1 | command 2 | command 3
Functional specifications :
Will command 1 Of stdout Send to command 2 Of stdin, command 2 Of stdout Send to command 3 Of stdin
All commands will be in the current shell The child of the process shell In process execution
Combine the functions of multiple tools
Be careful ;stderr By default, it cannot be forwarded through the pipeline , You can use 2&>1 or | & Realization , The format is as follows : command 1 2>&1 | command 2 command 1 |& command 2

In the pipe - Symbol
tar -cvf - /home | tar -xvf -
take home The files inside are packed , But the packaged data is not recorded to a file , It's transmitted to stdout, After passing through the pipe , take tar -cvf - /home To the back tar -xvf -, This one in the back - Is to go to the previous command stdout, So there is no need for temporary file

tee command
You can use tee Command redirects to multiple targets
command 1 | tee [-a] file name | command 2
-a Additional function : Save the output of different stages Troubleshooting of complex pipelines View and record the output at the same time

边栏推荐
- Oil monkey script learning
- Insomnia last night
- CS5463代码模块解析(包含下载链接)
- [sword finger offer] 50 First character that appears only once
- 【Flutter 問題系列第 71 篇】Flutter 中 Uint8List 和 Image 之間的相互轉換
- 自媒体行业内卷严重:企业自媒体应该何去何从
- Junior, it's not easy!
- Chapter V virtual memory exercise
- Tanghongbin, Yaya live CTO: to truly localize, the product should not have the attribute of "origin"
- [matlab] function definition and use
猜你喜欢
![[数学建模]Matlab非线性规划之fmincon()函数](/img/fc/46949679859b1369fcc83d0d8b637c.png)
[数学建模]Matlab非线性规划之fmincon()函数

See fengzhixia | FENGZikai, the originator of Guoman, for exclusive sale of Digital Collections

一张能卖上千万,商家扩张比玩家还快:球星卡的江湖你不懂

两栏布局左边图片显示部分由右边内容高度决定
![[deep learning] (3) encoder mechanism in transformer, complete pytoch code attached](/img/cb/d385bee7a229e8d11f5fa8af66311f.gif)
[deep learning] (3) encoder mechanism in transformer, complete pytoch code attached

在QT进行cin(全网最清晰教程)

C# 面试题目_20220627记录一下
![[Chapter 2 of word tutorial series] how to set the table on each page to have a header in word](/img/1a/8416d2c48bf1ddcc45e0c5d9acf242.png)
[Chapter 2 of word tutorial series] how to set the table on each page to have a header in word

WEB API学习笔记1

Leetcode detailed explanation of stack type
随机推荐
【深度学习】(2) Transformer 网络解析,代码复现,附Pytorch完整代码
Flowable boundary timer
YuMinHong set up two funds funded by his hometown
在DialogFragment的onStop(完全不可见)时调用dismiss退出界面报错解决办法
[stm32 Hal library] RTC and BKP drives
[matlab] function definition and use
[flutter issues Series title 71] Mutual Conversion between uint8list and Image in flutter
WEB API学习笔记1
Is it safe to open a stock account by mobile phone?
Insomnia last night
[sword finger offer] 50 First character that appears only once
Would like to ask, how to open a stock account? Is it safe to open an account online?
Mathematical knowledge: finding combinatorial number I - finding combinatorial number
LeetCode 324 擺動排序 II[排序 雙指針] HERODING的LeetCode之路
note
Design e-commerce seckill system
自媒体行业内卷严重:企业自媒体应该何去何从
Chapter II Classic synchronous exercises
[chapter 71 of the flutter problem series] mutual conversion between uint8list and image in flutter
Lost in cloud computing