先来回顾一下管道,通过管道符号,我们可以将命令的输出作为标准输入到其他的命令:
$ cat txt | grep a | less -S
mkfifo 可以创建一个命名管道,我们可以将一个终端中运行的结果通过这个命名管道,在另外一个终端访问。
首先创建一个命名管道:
$ mkfifo pipe1$ lspipe1prw-rw-r-- 1 yzpeng yzpeng 0 1月 23 15:11 pipe1
可以看到文件类型都不一样, p 。
接着就可以将命令的结果重定向到该管道文件中:
可以看到,shell 正在等待我们的使用。
这时候在其他终端中进入文件目录访问该命名管道:
$ cat pipe10.bin1.pipeline2.data3.biosoftarchivejimmymessminiconda3
而另外一边也同时结束了:
ps:乍一看,好像也没有什么用呀~
或许以后会有大帮助吧。
看看它的帮助文档:
$ man mkfifo | catMKFIFO(1) User Commands MKFIFO(1)NAMEmkfifo - make FIFOs (named pipes)SYNOPSISmkfifo [OPTION]... NAME...DESCRIPTIONCreate named pipes (FIFOs) with the given NAMEs.Mandatory arguments to long options are mandatory for short optionstoo.-m, --mode=MODEset 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 SMACKsecurity context to CTX--help display this help and exit--versionoutput version information and exitAUTHORWritten by David MacKenzie.REPORTING BUGSGNU coreutils online help: <https://www.gnu.org/software/coreutils/>Report mkfifo translation bugs to <https://translationpro‐ject.org/team/>COPYRIGHTCopyright © 2018 Free Software Foundation, Inc. License GPLv3+: GNUGPL 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 ALSOmkfifo(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)
