先来回顾一下管道,通过管道符号,我们可以将命令的输出作为标准输入到其他的命令:
$ cat txt | grep a | less -S
mkfifo 可以创建一个命名管道,我们可以将一个终端中运行的结果通过这个命名管道,在另外一个终端访问。
首先创建一个命名管道:
$ mkfifo pipe1
$ ls
pipe1
prw-rw-r-- 1 yzpeng yzpeng 0 1月 23 15:11 pipe1
可以看到文件类型都不一样, p
。
接着就可以将命令的结果重定向到该管道文件中:
可以看到,shell 正在等待我们的使用。
这时候在其他终端中进入文件目录访问该命名管道:
$ cat pipe1
0.bin
1.pipeline
2.data
3.biosoft
archive
jimmy
mess
miniconda3
而另外一边也同时结束了:
ps:乍一看,好像也没有什么用呀~
或许以后会有大帮助吧。
看看它的帮助文档:
$ man mkfifo | cat
MKFIFO(1) User Commands MKFIFO(1)
NAME
mkfifo - make FIFOs (named pipes)
SYNOPSIS
mkfifo [OPTION]... NAME...
DESCRIPTION
Create named pipes (FIFOs) with the given NAMEs.
Mandatory arguments to long options are mandatory for short options
too.
-m, --mode=MODE
set file permission bits to MODE, not a=rw - umask
-Z set the SELinux security context to default type
--context[=CTX]
like -Z, or if CTX is specified then set the SELinux or SMACK
security context to CTX
--help display this help and exit
--version
output version information and exit
AUTHOR
Written by David MacKenzie.
REPORTING BUGS
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report mkfifo translation bugs to <https://translationpro‐
ject.org/team/>
COPYRIGHT
Copyright © 2018 Free Software Foundation, Inc. License GPLv3+: GNU
GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
mkfifo(3)
Full documentation at: <https://www.gnu.org/software/coreutils/mkfifo>
or available locally via: info '(coreutils) mkfifo invocation'
GNU coreutils 8.30 September 2019 MKFIFO(1)