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

Redirect and piping and tr tee commands

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

1. Redirect

Input redirection is to overwrite or append the execution result or string of the command to a file

Command: > (overwrite) > > (append)

There are three types of linux output:

Standard input 0: keyboard input

Standard output 1: default output to terminal window

Error output 2: default output to terminal window

According to the output result, the output is redirected to the file:

Overwrite correct output and redirect to file

2 > overwrite error output redirected to file

2 > > append error output redirects to file

& > overwrite all output redirects to files

Append all output redirects to the file

> file > & 1 overwrites all output redirects to files

Merge multiple programs and redirect to a file

(ls;pwd) > F1 multiple command redirection

> the contents of the file will be overwritten

Set-C: it is forbidden to overwrite existing files, but you can add mandatory overrides: > |

Set + C: allow override

> > add content on the basis of the original content

Input redirection

Command:

< 将文件中的内容传递给命令执行 cat < /etc/fstab cat &1 |Command2 Command1 |& Command2 [root@localhost ~]# xecho asdfasdf 2>

& 1 | tr "Amurz" 'Amurz'

BASH: XECHO: command not found.

A similar command is: 'ECHO'

3. Tr command

Options:

-d info: delete information matching to info

[root@localhost ~] # echo abcdefg | tr-d abc

Defg

-c info: complement, except for info

[root@localhost ~] # echo abcdefg | tr-cd abc

Abc [root@localhost ~] #

-s info: remove the duplicate info and keep one

[root@localhost ~] # echo aabbbcc | tr-s ab

Abcc

'AmurZ'aMuzhuang: convert all uppercase characters to lowercase

[root@localhost ~] # echo aabbbcc | tr'amurz''AmurZ'

AABBBCC

-t info1 info2: replace by bit matching. Bits that do not match are not replaced.

[root@localhost ~] # echo abcdef | tr-t 'abcde'' 11'

11cdef

Info1 info2: replace all the information in info1 with the last bit of info2 that matches.

[root@localhost ~] # echo abcdef | tr 'abcde'' 11'

11111f

4. Tee command

Transfer ancient information from the upper level of the pipeline, save it to a file, and display the wound on the screen.

Ls | tee / testdir/ls.log | tr'amurz 'Amurz' > / tmp/who.out

The default is override-an is appended

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

Network Security

Wechat

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

12
Report