The xargs Command

Configurare noua (How To)


xargs is a command for building execution pipelines using the standard data streams. By using xargs we can make commands such as echo, rm, and mkdir accept standard input as arguments. Xargs will accept piped input. It can also accept input from a file. xargs uses that input as parameters for the commands we’ve told it to work with. If we do not tell xargs to work with a specific command it will default to use echo.

We can use that to demonstrate how xargs will always generate a single line of output, even from multi-line input.


Pasi de urmat

If we use the -1 (list one file per line) option with ls, we get a single column of filenames.

ls -1 ./*.sh

This lists the shell script files in the current directory.

We get a single column as expected. If we pipe it through xargs what do we get?

ls -1 ./*.sh | xargs

The output is written to the terminal window, as one long stream of text.

It’s this capability that let’s xargs feed parameters into other commands.

Tip solutie



(8 din 27 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?