XWLinux

xargs

Przekazanie outputu do innej komendy.

Opis

xargs — czyta stdin i buduje komendy. -I (replace string), -L (lines), -n (n args per cmd), -d (delimiter), -0 (null-delimited), -P (parallel), -r (no-run-if-empty), -a (file instead of stdin). find . -name '*.log' -print0 | xargs -0 rm = usuń logi.

Przykłady

$ find . -name '*.log' -print0 | xargs -0 rm
Usuń wszystkie .log
$ cat names.txt | xargs -I{} echo 'Hello {}'
Substytucja (I)
$ ls *.jpg | xargs -n5 convert -resize 50%
Batch convert (5 at a time)
$ cat urls.txt | xargs -P4 -n1 curl -sO
Pobierz 4 URL-e równolegle
$ find . -name '*.tmp' -print0 | xargs -0 -r rm
Usuń .tmp (bez run if empty)

Flagi

FlagaOpis
-I Replace string ({} = placeholder)
-L Liczba linii na komendę
-n Liczba argów na komendę
-d Delimiter
-0 Null-delimited (z find -print0)
-P Parallel (liczba procesów)
-r No-run-if-empty
-a Czytaj z pliku (zamiast stdin)
-0 Null-delimited (find -print0)