← 返回命令列表

Linux command

ifne 命令

文本

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Run command if input

command1 | ifne command2

Delete file if results

find . -empty | ifne xargs rm

Invert condition

command | ifne -n echo "no output"

Mail if errors

make 2>&1 | ifne mail -s "errors" [admin]

说明

ifne ("if not empty") reads from standard input and runs the given command only if that input is non-empty. The buffered input is then re-emitted on the command's stdin, so the consumer sees the original stream unchanged. With -n, the behavior is inverted: the command runs only if standard input is empty (useful for handling "nothing to do" branches in scripts). This makes ifne the natural complement to filters that may produce no output: pipelines like find ... -print0 | ifne xargs -0 rm or make 2>&1 | ifne mail -s "errors" admin stay silent when there is nothing to do.

参数

-n
Run if NO input.
--help
Display help information.

FAQ

What is the ifne command used for?

ifne ("if not empty") reads from standard input and runs the given command only if that input is non-empty. The buffered input is then re-emitted on the command's stdin, so the consumer sees the original stream unchanged. With -n, the behavior is inverted: the command runs only if standard input is empty (useful for handling "nothing to do" branches in scripts). This makes ifne the natural complement to filters that may produce no output: pipelines like find ... -print0 | ifne xargs -0 rm or make 2>&1 | ifne mail -s "errors" admin stay silent when there is nothing to do.

How do I run a basic ifne example?

Run `command1 | ifne command2` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -n do in ifne?

Run if NO input.