tech:notes_commande_xargs
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| tech:notes_commande_xargs [2026/04/30 11:20] – Jean-Baptiste | tech:notes_commande_xargs [2026/06/07 19:12] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Notes commande xargs | ||
| + | |||
| + | |||
| + | Strip char / trim => utiliser `xargs` ex : | ||
| + | ~~~bash | ||
| + | load5=$(echo $UPTIME | awk -F, ' | ||
| + | ~~~ | ||
| + | |||
| + | md5sum multithread | ||
| + | ~~~bash | ||
| + | #find . -not -name " | ||
| + | find . -not -name " | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | dig A +short acme.local | xargs -P5 -I ' | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | cat 20_ok_ping.txt | xargs -L1 -I ' | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | pidof sleep | xargs kill -9 | ||
| + | ~~~ | ||
| + | |||
| + | Renommer tous les fichiers *.txt d'un répertoire | ||
| + | ~~~bash | ||
| + | ls -1 ${repertoire}/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | cat bash-xargs-demo.txt | xargs -I % sh -c 'echo %; mkdir %' | ||
| + | xargs -a bash-xargs-demo.txt -I % sh -c 'echo %; mkdir %' | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Prompt before launch | ||
| + | ~~~bash | ||
| + | find * | xargs -p rm -rf | ||
| + | ~~~ | ||
| + | |||
| + | use xargs to copy a file to multiple directories at once; in this example we are trying to copy the file. | ||
| + | ~~~bash | ||
| + | echo ./ | ||
| + | ~~~ | ||
| + | |||
| + | A la place de ' | ||
| + | ~~~bash | ||
| + | echo /etc/* |xargs -n 1 basename | ||
| + | ~~~ | ||
| + | |||
| + | Avec délimitateur | ||
| + | ~~~ | ||
| + | $ echo 'my new file' | xargs -d ' | ||
| + | $ ls -l | ||
| + | total 0 | ||
| + | -rw-r--r--. 1 shs shs 0 Oct 15 12:41 file1 | ||
| + | -rw-r--r--. 1 shs shs 0 Oct 15 12:41 file2 | ||
| + | -rw-r--r--. 1 shs shs 0 Oct 15 12:41 file3 | ||
| + | -rw-r--r--. 1 shs shs 0 Oct 15 12:57 'my new file' | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | $ echo " | ||
| + | 1 2 3 4 5 | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | $ echo " | ||
| + | 1 | ||
| + | 2 | ||
| + | 3 | ||
| + | 4 | ||
| + | 5 | ||
| + | ~~~ | ||
| + | |||
| + | Copie de fichiers | ||
| + | ~~~bash | ||
| + | find /backup/ -type f | xargs -n1 -i cp {} / | ||
| + | ~~~ | ||
| + | |||
| + | Curl - flood | ||
| + | ~~~bash | ||
| + | seq 1 200 | xargs -n1 -P10 curl " | ||
| + | ~~~ | ||
| + | |||
| + | Curl - test urls | ||
| + | ~~~bash | ||
| + | xargs -a urls.txt -L1 -I ' | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Curl can now fetch several websites in parallel | ||
| + | ~~~bash | ||
| + | curl --parallel --parallel-immediate --parallel-max 3 --config websites.txt | ||
| + | ~~~ | ||
| + | |||
| + | `websites.txt` | ||
| + | ~~~python | ||
| + | url = " | ||
| + | url = " | ||
| + | url = " | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ### xargs avec Ansible | ||
| + | |||
| + | Voir aussi : | ||
| + | * [[Ansible - Accélérer Ansible grâce au module Mitogen]] | ||
| + | * traitements_paralleles [[notes_ansible]] | ||
| + | |||
| + | ~~~bash | ||
| + | xargs -a inventory.lst -L1 -I % -P50 bash -c " | ||
| + | ~~~ | ||
| + | |||
| + | 4 GB RAM is recommended per 100 forks... about 100MB per fork... The baseline value for [CPU capacity for forks] is 4 forks per core. | ||
| + | |||
| + | Ref : https:// | ||
| + | |||
| + | |||
| + | |||
| + | |||
