Jos*_*muk 1 command-line redirect tee
我只想将 find 命令的非空输出保存到文件中。如果没有输出文件则不应创建。
$ ls folder
aa
$ find . -name 'bb' | tee file
$ cat file
$ ls folder
aa file
Run Code Online (Sandbox Code Playgroud)
怎么做?
ifne包中的实用程序moreutils应该可以完成您想要的任务:
$ find . -name 'bb' | ifne tee file
Run Code Online (Sandbox Code Playgroud)
从手册页:
描述
当且仅当标准输入不为空时, ifne才会运行以下命令。