LinuxCommandLibrary

ifne

runs a command only if there is input

TLDR

Run command if input

$ command1 | ifne command2
copy
Delete file if results
$ find . -empty | ifne xargs rm
copy
Invert condition
$ command | ifne -n echo "no output"
copy
Mail if errors
$ make 2>&1 | ifne mail -s "errors" [admin]
copy

SYNOPSIS

ifne [options] command [args]

DESCRIPTION

ifne runs a command only if there is input. It reads stdin and passes it to the command if non-empty.
The tool is useful in pipelines where subsequent commands should only run when there's data. The -n flag inverts the behavior.

PARAMETERS

COMMAND

Command to run.
ARGS
Command arguments.
-n
Run if NO input.
--help
Display help information.

CAVEATS

Part of moreutils. Buffers input. Stdin passed to command.

HISTORY

ifne is part of moreutils, a collection of Unix tools by Joey Hess.

SEE ALSO

xargs(1), moreutils(7), test(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community