24 December 2021

In my daily work sometimes I need to execute commands that doesn't handle piped input,
fortunately there is a xargs that could be used.

xargs run COMMAND with arguments INITIAL-ARGS and more arguments read from input,
it is mainly created for use with commands not built to handle piped input or standard input such as cp, rm, du, ... .

Note: all example below could be execute in a container:

docker run -it  ubuntu /bin/bash

Example:

ls /etc/h* | xargs -I {} sh -c 'du -h {}'

The output is:

4.0K	/etc/host.conf
4.0K	/etc/hostname
4.0K	/etc/hosts

Explanation about example:

References

xargs --help