stdout和/dev/stdout之间的区别 [英] Difference between stdout and /dev/stdout
问题描述
bala@hp:~$ echo "Hello World" > stdout
bala@hp:~$ cat stdout
Hello World
bala@hp:~$ echo "Hello World" > /dev/stdout
Hello World
请澄清stdout
和/dev/stdout
注意:
bala@hp:~$ file stdout
stdout: ASCII text
bala@hp:~$ file /dev/stdout
/dev/stdout: symbolic link to `/proc/self/fd/1'
请帮助您了解区别.
推荐答案
在您的情况下
-
stdout
是普通文件,在您运行命令的同一目录中创建.
stdout
is a normal file, created in the same directory where you're running the command.
因此,当您将echo
的输出重定向到stdout
时,它将被写入文件.您需要执行cat
(例如,您在此处所做的)才能在此处在屏幕上看到内容.
So, when you're redirecting the output of echo
to stdout
, it is written to the file. You need to do cat
(as example, here you did) in order to see the content on screen here.
/dev/stdout
是 设备文件,这是/proc/self/fd/1
的链接,这意味着它引用了当前进程保存的文件描述符1.
/dev/stdout
is a device file, which is a link to /proc/self/fd/1
, which means it is referring to the file descriptor 1 held by the current process.
因此,当您将echo
的输出重定向到/dev/stdout
时,它会直接发送到标准输出(屏幕).
So, when you're redirecting the output of echo
to /dev/stdout
, it is sent to the standard output (the screen) directly.
这篇关于stdout和/dev/stdout之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!