Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Redirect and piping and tr tee commands

Shulou Source: shulou.com Published: 2022-06-01 02:21:21 09月16日 Update

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

Tags: Command file output result content error input pipe information similarity character screen standard terminal script parameter base multiple multiple uppercase Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei vpn macOS Xiaomi Shulou Tech Info