Shell中的重定向

Linux专栏_章节六_shell中的IO重定向 重定向 通常来说, shell的接收键盘的输入, 然后处理, 并且将处理结果显示在屏幕上. 因此, 键盘输入被称为是 “标准输入”; 屏幕输出被称为是 “标准输出”. 然而我们可以改变shell获得输入的方式, 使其不仅是从键盘获取输入. 同时, 我们也可以改变shell输出的对象, 使其不只是输出在屏幕上. 本章, 我们将用到的命令如下 cat: 合并文件 sort: 对文本行排序 uniq: 报告或者删除文件中重复的行 wc: 打印文件中的换行符, 字和字节的个数 grep: 打印匹配行 head: 输 阅读详情

Working with redirections in bash is really easy once you realize that it's all about manipulating file descriptors. When bash starts it opens the three standard file descriptors: stdin (file descriptor 0), stdout (file descriptor 1), and stderr (file descriptor 2). You can open more file descriptors (such as 3, 4, 5, ...), and you can close them. You can also copy file descriptors. And you can write to them and read from them.

File descriptors always point to some file (unless they're closed). Usually when bash starts all three file descriptors, stdin, stdout, and stderr, point to your terminal. The input is read from what you type in the terminal and both outputs are sent to the terminal.

Assuming your terminal is /dev/tty0, here is how the file descriptor table looks like when bash starts:

When bash runs a command it forks a child process (see man 2 fork) that inherits all the file descriptors from the parent process, then it sets up the redirections that you specified, and execs the command (seeman 3 exec).

To be a pro at bash redirections all you need to do is visualize how the file descriptors get changed when redirections happen. The graphics illustrations will help you.

1. Redirect the standard output of a command to a file

$ command >file

Operator > is the output redirection operator. Bash first tries to open the file for writing and if it succeeds it sends the stdout of command to the newly opened file. If it fails opening the file, the whole command fails.

Writing command >file is the same as writing command 1>file. The number 1 stands for stdout, which is the file descriptor number for standard output.

Here is how the file descriptor table changes. Bash opens file and replaces file descriptor 1 with the file descriptor that points to file. So all the output that gets written to file descriptor 1 from now on ends up being written to file:

In general you can write command n>file, which will redirect the file descriptor n to file.

For example,

$ ls > file_list

Redirects the output of the ls command to the file_list file.

2. Redirect the standard error of a command to a file

$ command 2> file

Here bash redirects the stderr to file. The number 2 stands for stderr.

Here is how the file descriptor table changes:

Bash opens file for writing, gets the file descriptor for this file, and it replaces file descriptor 2 with the file descriptor of this file. So now anything written to stderr gets written to file.

3. Redirect both standard output and standard error to a file

$ command &>file

This one-liner uses the &> operator to redirect both output streams - stdout and stderr - from command tofile. This is bash's shortcut for quickly redirecting both streams to the same destination.

Here is how the file descriptor table looks like after bash has redirected both streams:

As you can see both stdout and stderr now point to file. So anything written to stdout and stderr gets written to file.

There are several ways to redirect both streams to the same destination. You can redirect each stream one after another:

$ command >file 2>&1

This is a much more common way to redirect both streams to a file. First stdout is redirected to file, and then stderr is duplicated to be the same as stdout. So both streams end up pointing to file.

When bash sees several redirections it processes them from left to right. Let's go through the steps and see how that happens. Before running any commands bash's file descriptor table looks like this:

Now bash processes the first redirection >file. We've seen this before and it makes stdout point tofile:

Next bash sees the second redirection 2>&1. We haven't seen this redirection before. This one duplicates file descriptor 2 to be a copy of file descriptor 1 and we get:

Both streams have been redirected to file.

However be careful here! Writing:

command >file 2>&1

Is not the same as writing:

$ command 2>&1 >file

The order of redirects matters in bash! This command redirects only the standard output to the file. The stderr will still print to the terminal. To understand why that happens, let's go through the steps again. So before running the command the file descriptor table looks like this:

Now bash processes redirections left to right. It first sees 2>&1 so it duplicates stderr to stdout. The file descriptor table becomes:

Now bash sees the second redirect >file and it redirects stdout to file:

Do you see what happens here? Stdout now points to file but the stderr still points to the terminal! Everything that gets written to stderr still gets printed out to the screen! So be very, very careful with the order of redirects!

Also note that in bash, writing this:

$ command &>file

Is exactly the same as:

$ command >&file

The first form is preferred however.

4. Discard the standard output of a command

$ command > /dev/null

The special file /dev/null discards all data written to it. So what we're doing here is redirecting stdout to this special file and it gets discarded. Here is how it looks from the file descriptor table's perspective:

Similarly, by combining the previous one-liners, we can discard both stdout and stderr by doing:

$ command >/dev/null 2>&1

Or just simply:

$ command &>/dev/null

File descriptor table for this feat looks like this:

5. Redirect the contents of a file to the stdin of a command

$ command <file

Here bash tries to open the file for reading before running any commands. If opening the file fails, bash quits with error and doesn't run the command. If opening the file succeeds, bash uses the file descriptor of the opened file as the stdin file descriptor for the command.

After doing that the file descriptor table looks like this:

Here is an example. Suppose you want to read the first line of the file in a variable. You can simply do this:

$ read -r line < file

Bash's built-in read command reads a single line from standard input. By using the input redirection operator < we set it up to read the line from the file.

6. Redirect a bunch of text to the stdin of a command

$ command <<EOL
your
multi-line
text
goes
here
EOL

Here we use the here-document redirection operator <<MARKER. This operator instructs bash to read the input from stdin until a line containing only MARKER is found. At this point bash passes the all the input read so far to the stdin of the command.

Here is a common example. Suppose you've copied a bunch of URLs to the clipboard and you want to remove http:// part of them. A quick one-liner to do this would be:

$ sed 's|http://||' <<EOL
http://url1.com
http://url2.com
http://url3.com
EOL

Here the input of a list of URLs is redirected to the sed command that strips http:// from the input.

This example produces this output:

url1.com
url2.com
url3.com

7. Redirect a single line of text to the stdin of a command

$ command <<< "foo bar baz"

For example, let's say you quickly want to pass the text in your clipboard as the stdin to a command. Instead of doing something like:

$ echo "clipboard contents" | command

You can now just write:

$ command <<< "clipboard contents"

This trick changed my life when I learned it!

8. Redirect stderr of all commands to a file forever

$ exec 2>file
$ command1
$ command2
$ ...

This one-liner uses the built-in exec bash command. If you specify redirects after it, then they will last forever, meaning until you change them or exit the script/shell.

In this case the 2>file redirect is setup that redirects the stderr of the current shell to the file. Running commands after setting up this redirect will have the stderr of all of them redirected to file. It's really useful in situations when you want to have a complete log of all errors that happened in the script, but you don't want to specify 2>file after every single command!

In general exec can take an optional argument of a command. If it's specified, bash replaces itself with the command. So what you get is only that command running, and there is no more shell.

9. Open a file for reading using a custom file descriptor

$ exec 3<file

Here we use the exec command again and specify the 3<file redirect to it. What this does is opens the file for reading and assigns the opened file-descriptor to the shell's file descriptor number 3. The file descriptor table now looks like this:

Now you can read from the file descriptor 3, like this:

$ read -u 3 line

This reads a line from the file that we just opened as fd 3.

Or you can use regular shell commands such as grep and operate on file descriptor 3:

$ grep "foo" <&3

What happens here is file descriptor 3 gets duplicated to file descriptor 1 - stdin of grep. Just remember that once you read the file descriptor it's been exhausted and you need to close it and open it again to use it. (You can't rewind an fd in bash.)

After you're done using fd 3, you can close it this way:

$ exec 3>&-

Here the file descriptor 3 is duped to -, which is bash's special way to say "close this fd".

10. Open a file for writing using a custom file descriptor

$ exec 4>file

Here we simply tell bash to open file for writing and assign it number 4. The file descriptor table looks like this:

As you can see file descriptors don't have to be used in order, you can open any file descriptor number you like from 0 to 255.

Now we can simply write to the file descriptor 4:

$ echo "foo" >&4

And we can close the file descriptor 4:

$ exec 4>&-

It's so simple now once we learned how to work with custom file descriptors!

11. Open a file both for writing and reading

$ exec 3<>file

Here we use bash's diamond operator <>. The diamond operator opens a file descriptor for both reading and writing.

So for example, if you do this:

$ echo "foo bar" > file   # write string "foo bar" to file "file".
$ exec 5<> file           # open "file" for rw and assign it fd 5.
$ read -n 3 var <&5       # read the first 3 characters from fd 5.
$ echo $var

This will output foo as we just read the first 3 chars from the file.

Now we can write some stuff to the file:

$ echo -n + >&5           # write "+" at 4th position.
$ exec 5>&-               # close fd 5.
$ cat file

This will output foo+bar as we wrote the + char at 4th position in the file.

12. Send the output from multiple commands to a file

$ (command1; command2) >file

This one-liner uses the (commands) construct that runs the commands a sub-shell. A sub-shell is a child process launched by the current shell.

So what happens here is the commands command1 and command2 get executed in the sub-shell, and bash redirects their output to file.

13. Execute commands in a shell through a file

Open two shells. In shell 1 do this:

mkfifo fifo
exec < fifo

In shell 2 do this:

exec 3> fifo;
echo 'echo test' >&3

Now take a look in shell 1. It will execute echo test. You can keep writing commands to fifo and shell 1 will keep executing them.

Here is how it works.

In shell 1 we use the mkfifo command to create a named pipe called fifo. A named pipe (also called a FIFO) is similar to a regular pipe, except that it's accessed as part of the file system. It can be opened by multiple processes for reading or writing. When processes are exchanging data via the FIFO, the kernel passes all data internally without writing it to the file system. Thus, the FIFO special file has no contents on the file system; the file system entry merely serves as a reference point so that processes can access the pipe using a name in the file system.

Next we use exec < fifo to replace current shell's stdin with fifo.

Now in shell 2 we open the named pipe for writing and assign it a custom file descriptor 3. Next we simply write echo test to the file descriptor 3, which goes to fifo.

Since shell 1's stdin is connected to this pipe it executes it! Really simple!

14. Access a website through bash

$ exec 3<>/dev/tcp/www.google.com/80
$ echo -e "GET / HTTP/1.1\n\n" >&3
$ cat <&3

Bash treats the /dev/tcp/host/port as a special file. It doesn't need to exist on your system. This special file is for opening tcp connections through bash.

In this example we first open file descriptor 3 for reading and writing and point it to/dev/tcp/www.google.com/80 special file, which is a connection to www.google.com on port 80.

Next we write GET / HTTP/1.1\n\n to file descriptor 3. And then we simply read the response back from the same file descriptor by using cat.

Similarly you can create a UDP connection through /dev/udp/host/port special file.

With /dev/tcp/host/port you can even write things like port scanners in bash!

15. Prevent overwriting the contents of a file when redirecting output

$ set -o noclobber

This turns on the noclobber option for the current shell. The noclobber option prevents you from overwriting existing files with the > operator.

If you try redirecting output to a file that exists, you'll get an error:

$ program > file
bash: file: cannot overwrite existing file

If you're 100% sure that you want to overwrite the file, use the >| redirection operator:

$ program >| file

This succeeds as it overrides the noclobber option.

16. Redirect standard input to a file and print it to standard output

$ command | tee file

The tee command is super handy. It's not part of bash but you'll use it often. It takes an input stream and prints it both to standard output and to a file.

In this example it takes the stdout of command, puts it in file, and prints it to stdout.

Here is a graphical illustration of how it works:

17. Send stdout of one process to stdin of another process

$ command1 | command2

This is simple piping. I'm sure everyone is familiar with this. I'm just including it here for completeness. Just to remind you, a pipe connects stdout of command1 with the stdin of command2.

It can be illustrated with a graphic:

As you can see, everything sent to file descriptor 1 (stdout) of command1 gets redirected through a pipe to file descriptor 0 (stdin) of command2.

You can read more about pipes in man 2 pipe.

18. Send stdout and stderr of one process to stdin of another process

$ command1 |& command2

This works on bash versions starting 4.0. The |& redirection operator sends both stdout and stderr of command1 over a pipe to stdin of command2.

As the new features of bash 4.0 aren't widely used, the old, and more portable way to do the same is:

$ command1 2>&1 | command2

Here is an illustration that shows what happens with file descriptors:

First command1's stderr is redirected to stdout, and then a pipe is setup between command1's stdout and command2's stdin.

19. Give file descriptors names

$ exec {filew}>output_file

Named file descriptors is a feature of bash 4.1. Named file descriptors look like {varname}. You can use them just like regular, numeric, file descriptors. Bash internally chooses a free file descriptor and assigns it a name.

20. Order of redirections

You can put the redirections anywhere in the command you wish. Check out these 3 examples, they all do the same:

$ echo hello >/tmp/example

$ echo >/tmp/example hello

$ >/tmp/example echo hello

Got to love bash!

21. Swap stdout and stderr

$ command 3>&1 1>&2 2>&3

Here we first duplicate file descriptor 3 to be a copy of stdout. Then we duplicate stdout to be a copy of stderr, and finally we duplicate stderr to be a copy of file descriptor 3, which is stdout. As a result we've swapped stdout and stderr.

Let's go through each redirection with illustrations. Before running the command, we've file descriptors pointing to the terminal:

Next bash setups 3>&1 redirection. This creates file descriptor 3 to be a copy of file descriptor 1:

Next bash setups 1>&2 redirection. This makes file descriptor 1 to be a copy of file descriptor 2:

Next bash setups 2>&3 redirection. This makes file descriptor 2 to be a copy of file descriptor 3:

If we want to be nice citizens we can also close file descriptor 3 as it's no longer needed:

$ command 3>&1 1>&2 2>&3 3>&-

The file descriptor table then looks like this:

As you can see, file descriptors 1 and 2 have been swapped.

22. Send stdout to one process and stderr to another process

$ command > >(stdout_cmd) 2> >(stderr_cmd)

This one-liner uses process substitution. The >(...) operator runs the commands in ... with stdin connected to the read part of an anonymous named pipe. Bash replaces the operator with the filename of the anonymous pipe.

So for example, the first substitution >(stdout_cmd) might return /dev/fd/60, and the second substitution might return /dev/fd/61. Both of these files are named pipes that bash created on the fly. Both named pipes have the commands as readers. The commands wait for someone to write to the pipes so they can read the data.

The command then looks like this:

$ command > /dev/fd/60 2> /dev/fd/61

Now these are just simple redirections. Stdout gets redirected to /dev/fd/60, and stderr gets redirected to /dev/fd/61.

When the command writes to stdout, the process behind /dev/fd/60 (process stdout_cmd) reads the data. And when the command writes to stderr, the process behind /dev/fd/61 (process stderr_cmd) reads the data.

23. Find the exit codes of all piped commands

Let's say you run several commands all piped together:

$ cmd1 | cmd2 | cmd3 | cmd4

And you want to find out the exit status codes of all these commands. How do you do it? There is no easy way to get the exit codes of all commands as bash returns only the exit code of the last command.

Bash developers thought about this and they added a special PIPESTATUS array that saves the exit codes of all the commands in the pipe stream.

The elements of the PIPESTATUS array correspond to the exit codes of the commands. Here's an example:

$ echo 'pants are cool' | grep 'moo' | sed 's/o/x/' | awk '{ print $1 }'
$ echo ${PIPESTATUS[@]}
0 1 0 0

In this example grep 'moo' fails, and the 2nd element of the PIPESTATUS array indicates failure.

Shoutouts

Shoutouts to bash hackers wiki for their illustrated redirection tutorial and bash version changes.

shell中的IO和重定向使用 标准I/O和重新定向 当shell启动,它继承三个文件:stdin,stdout和stderr。标准输入通常来自键盘。标准输出和标准错误通常是屏幕。但是很多时候你也许想从文件中读取输入或者把输出保存在文件中。这个时候你就可以使用I/O重新定向,见下表 重新定向操作符表 重新定向操作符 作用 < 重新定向输入 > 重新定向输出 >> 追加输出 2&... 阅读详情

相关推荐

Shell脚本中的重定向操作

重定向是Shell脚本编程中常用的一种技术,它允许将命令的输入或输出从默认的标准位置重定向到其他位置。在本文中,我们将详细介绍Shell脚本中的重定向操作,并提供相应的源代码示例。错误重定向允许我们将命令的错误输出(标准错误)重定向到文件或其他位置。输出重定向允许我们将命令的输出发送到文件而不是默认的标准输出(通常是终端)。上述示例将ls命令执行时产生的错误输出重定向到名为error.txt的文件中。上述示例将命令的输出和错误合并,并将其重定向到名为output.txt的文件中。示例3:从文件中读取输入。

CodeVorter的博客 485

Shell--基础--13--重定向

Shell–基础–13–重定向 1、文件描述符 当执行shell命令时,会默认打开3个文件,每个文件有对应的文件描述符来方便我们使用: 所以我们平时在执行shell命令中,都默认是从键盘获得输入,并且将结果输出到控制台上。但是我们可以通过更改文件描述符默认的指向,从而实现输入输出的重定向。比如我们将1指向文件,那么标准的输出就会输出到文件中。 2、输出重定向 2.1、语法 我们使用>或者>>对输出做重定向,如果符号左边没有写值,那么默认就是1。 符号的右边可以是一个文件,也可以是一

zhou920786312的博客 1152

Shell编程中的重定向技巧

在Shell编程中,重定向是一种常用的技巧,可以将命令的输入、输出或错误流重定向到不同的位置,实现灵活的数据处理和流控制。追加重定向与输出重定向类似,但是不会覆盖目标文件的内容,而是将输出结果追加到文件末尾。输出重定向可以将命令的输出结果保存到文件中而不是显示在屏幕上。错误重定向可以将命令的错误输出保存到文件中。上述代码执行一个不存在的命令,并将输出和错误合并后保存到名为output_error.txt的文件中。上述代码执行一个不存在的命令,并将错误输出保存到名为error.txt的文件中。

TechInk的博客 186

Shell学习-13-Shell重定向

Shell学习-13-Shell重定向

时光 1820

Shell编程中的重定向操作符及其用法

将命令的输出重定向到/dev/null设备文件可以实现隐藏命令的输出。输出重定向操作符(>)用于将命令的标准输出重定向到指定的文件。上述代码将命令的标准输出和标准错误输出合并重定向到名为output_and_error.txt的文件中。合并输出和错误重定向操作符(&> 或者 >)用于将命令的标准输出和标准错误输出合并重定向到指定的文件。将命令的输出和错误都重定向到/dev/null设备文件可以实现完全隐藏命令的输出和错误。错误重定向操作符(2>)用于将命令的标准错误输出重定向到指定的文件。

TbbPuppet的博客 338

告别玄学调参:手把手教你用LSTM-AutoEncoder为传感器数据做异常检测(实战篇)

本文详细介绍了LSTM-AutoEncoder在传感器数据异常检测中的工程化实践,包括数据预处理、模型架构设计和生产环境部署策略。通过结合LSTM的时间序列处理能力和AutoEncoder的特征提取优势,该方法能够有效识别温湿度、PM2.5等传感器数据的异常模式,适用于工业物联网和室内空气质量监测等场景。

weixin_29212429的博客 477

【Linux】shell编程5(Shell脚本常见错误示例、Shell脚本调试技巧、shell脚本开发环境配置和优化、vim常用快捷操作、seq 序列化产生数字)

1、 bash [-nvx] script.sh #-n:不会执行该脚本,仅查询脚本语法是否有问题,并给出错误提示 #-v:执行脚本时,先将脚本的内容输出到屏幕上,然后执行脚本,如果有错误,会给出 错误提示 #-x:将执行的脚本的内容及输出显示到屏幕上, 2、优化vim编辑配置 3、seq常用选项 -w -sf -f

Linux小白一只~正处于学习阶段,觉得我写的还好的请多多给我点赞呀,谢谢大家!!(๑>ڡ<)☆ 3955

Node框架之NestJS入门学习

文章主要分为三部分:1 NestJS 与Egg对比2 NestJS 基础知识介绍3 使用NestJS快速搭建应用,实现CURD操作e-link文档Egg官网NestJS 官网NestJS中文文档(非官方)

十九万里的博客 4742

linux:用当前日期作为文件名,报错:模糊的重定向

当使用当前日期(年-月-日 时:分:秒)作为文件名称时,运行shell脚本后报错。

lemon9597的博客 1305

HTML5期末大作业:关于家乡介绍的HTML网页设计——郑州美景HTML+CSS(5页) 学生DW家乡介绍网页设计作业成品 web课程设计网页规划与设计

HTML5期末大作业:我的家乡——郑州美景HTML+CSS(5页) 学生DW网页设计作业成品 web课程设计网页规划与设计 计算机毕设网页设计源码 常见网页设计作业题材有 个人、 美食、 公司、 学校、 旅游、 电商、 宠物、 电器、 茶叶、 家居、 酒店、 舞蹈、 动漫、 明星、 服装、 体育、 化妆品、 物流、 环保、 书籍、 婚纱、 游戏、 节日、 戒烟、 电影、 摄影、 文化、 家乡、 鲜花、 礼品、 汽车、 其他 等网页设计题目, A+水平作业, 可满足大学生网页大作业网页设计需求, 喜

qq_365392777 1万+

如何用 OBProxy 实现 OceanBase 的最佳路由策略

本文基于业务中一类常见的路由问题展开,对OceanBase的路由功能及对应配置项做详细介绍,指导用户在业务实践中如何正确的配置路由策略及快速排查路由问题

OceanBase分布式数据库的博客 1680

Shell脚本的一些操作和知识

循环语句: Bash Shell中主要提供了三种循环方式:for、while和until。 一,for循环 for循环的运作方式,是讲串行的元素意义取出,依序放入指定的变量中,然后重复执行含括的命令区域(在do和done 之间),直到所有元素取尽为止。 其中,串行是一些字符串的组合,彼此用$IFS所定义的分隔符(如空格符)隔开,这些字符串称为字段。 for的语法结构如下: 1.

fengasdfgh的博客 292

ArcGIS图解建模工具与DEM提取山脊、山谷线(水文分析、表面分析)

参考汤国安、杨昕等编著的《地理信息系统空间分析实验教程第二版》 利用水文分析(流量)和表面分析(坡向变率)得到山脊和山谷线 文章目录1、基本概念1.1 正地形1.2 负地形正负地形的影响2、水文分析方法2.1 基本思想原理2.2 技术路线2.3 操作步骤2.3.1 正负地形的提取2.3.2 利用水文分析思想和工具提取研究区域的山脊线2.3.3 利用水文分析思想和工具提取研究区域的山谷线2.3.4 利用水文分析提取山脊线和山谷线结果3、表面分析方法3.1 基本思想原理3.2 技术路线3.3 操作步骤4、图.

fungis 1万+

详解shell中的几种标准输出重定向方式

shell重定向介绍 无论是用什麽语言开发的程序,都会处理外部的输入,然后将运算结果输出到指定的位置。在交互式的程序中,输入来自用户的键盘和鼠标,结果输出到用户的屏幕,甚至到其他播放设备中。而对于某些后台运行的程序,输入可能来自于外部的一些文件,运算的结果通常又需要写到其他的文件中。比如:程序在运行的过程中,会有一些关键性的信息,比如异常堆栈,外部接口调用情况等,这些都会统统写到日志文件里。 sh...

yuki5233的博客 2万+

如何在 Mac 上下载安装 Xcode——并为 iOS 开发更新它原文

下载 Xcode安装命令行工具打开新版本删除文件注意,我在下面的步骤中列出了一些终端命令。这些命令可以被输入到你现在的工作目录中。这意味着你不需要导航到任何特定的文件夹。如果你真的想这样做,你可以在输入下面的步骤中的命令之前先输入== cd==。这将使你返回到主文件夹。

专注于AI领域前沿知识,业余爱好开发软件 4666

NXP S32k3 MCAL ADC配置

S32K3 配置MCAL ADC

Leon_0125的博客 5071

Shell 中的重定向

符号名称说明示例输出重定向(覆盖) 将 stdout 重定向到文件>>输出追加(追加) 将 stdout 重定向到文件2>错误重定向(覆盖) 将 stderr 重定向到文件2>>错误追加(追加) 将 stderr 重定向到文件输入重定向从文件读取 stdin&>合并重定向(覆盖) 将 stdout 和 stderr 都重定向到文件 (Bash/Zsh)&>>合并追加(追加) 将 stdout 和 stderr 都重定向到文件 (Bash/Zsh)传统合并重定向功能同&>,兼容性更好。

龙卡的博客 1081

Python爬虫实战:全自动采集银行理财产品收益率数据

本文通过Playwright动态爬虫技术,成功实现了对银行理财产品收益率数据的实时采集,并通过 Pandas 数据清洗、SQLite 存储、调度自动化等模块,构建了一个可扩展的银行理财数据抓取系统。理财非儿戏,数据做决策。掌握银行收益信息是我们迈向理性投资的第一步。希望这套工具对你有所帮助!

2201_76125261的博客 1155

【Linux】简单实现shell中的重定向添加

重定向: 所谓重定向,是指把本来打印在显示器上的内容,通过一定的符号输出到了特定文件中。 用一句话概括重定向的本质就是:把文件描述符组里面的内容覆盖到一个新的文件中。 重定向符号: &gt;               输出重定向到一个文件或设备 覆盖原来的文件 &gt;!              输出重定向到一个文件或设备 强制覆盖原来的文件 &gt;&gt;           ...

流云 1028

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

解释linux中的三种重定向,Linux重定向及反弹shell详解

这里说Linux重定向的原因主要还是为了详细了解一下Linux中的反弹shell目录0x01 文件描述符0x02 重定向0x03 反弹shell0x04 交互重定向0x05 命令变形0x01 文件描述符Linux的文件描述符有以下三种标准输入:0标准输出:1错误输出:2对于文件描述符就先知道这些就可以了,具体的使用会在重定向中来说,重定向就是对文件描述符的操作0x02 重定向重定向主要分为以下两种...

weixin_39767513的博客 617

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

shell 输出重定向在调试中的使用

对于任何一条linux 命令执行,它会是这样一个过程: 一个命令执行了: 先有一个输入:输入可以从键盘,也可以从文件得到 命令执行完成:成功了,会把成功结果输出到屏幕:standard output默认是屏幕 命令执行有错误:会把错误也输出到屏幕上面:standard error默认也是指的屏幕

a1a2a3a4的专栏 1127

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Linux Shell 编程中的输入输出重定向

本篇概要:1. 输入输出重定向;2. 文件描述符与错误重定向;3. 在脚本中重定向输入输出;4. 管道。 1. 输入输出重定向; 标准输入:键盘 标准输出:终端显示器 在使用 Shell 命令时,通常都是通过键盘对命令输入数据,而通过显示器可以查看命令输出的结果。 但是在很多时候我们需要使用文件来作为命令输入的数据,同时也需要将命令的输出保存在文件中。这时候就需要用到输入输出的重定向。也就是说将...

业余敲代码 571

shell脚本中的EOF以及文件重定向

(内容)  EOF  可以把EOF替换成其他东西(分解符)  意思是把内容当作标准输入传给程序 这里再简要回顾一下 符。在该分界符以后的内容都被当作输入,直到shell又看到该分界符(位于单独的一行)。这个  分界符可以是你所定义的任何字符串。 常用文件重定向: command > filename  把标准输出重定向到一个新文件中  command >> filen

huangmr的专栏 4971

Linux笔记之shell中的重定向

就像我们平时写的程序一样,一段程序会处理外部的输入,然后将运算结果输出到指定的位置。在交互式的程序中,输入来自用户的键盘和鼠标,结果输出到用户的屏幕,甚至播放设备中。而对于某些后台运行的程序,输入可能来自于外部的一些文件,运算的结果通常又写到其他的文件中。而且程序在运行的过程中,会有一些关键性的信息,比如异常堆栈,外部接口调用情况等,这些都会统统写到日志文件里。shell脚本也一样,但是我们一般在使用shell命令的时候,更多地还是通过键盘输入,然后在屏幕上查看命令的执行结果。

小勇博客 2869

运维面试必备:Shell脚本中的重定向(Redirection)操作及其用途

重定向(Redirection)是Shell脚本中一种强大的功能,它允许我们控制命令的输入来源和输出去向。通过重定向,我们可以将命令的输出发送到文件而不是屏幕,或者从文件而不是键盘获取输入。

qq_58299462的博客 963
上一篇: oozie server系统时钟偏差导致sqoop报错
下一篇: 什么是Here Document
DViewer
博客等级 码龄16年 16粉丝 6原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值