هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
Many commands do not read standard input; they need arguments. xargs reads words or lines from the pipe and puts them on the command line of another command. With -P it runs many copies at the same time — a simple way to make scripts faster.
Use -0 together with find -print0 so file names with spaces work.
طريقة الكتابة
COMMAND | xargs [OPTIONS] [COMMAND [ARG ...]]الخيارات 11
الأكثر استخدامًا
Options
-0,--null- Items end with a NUL character (use with
find -print0).
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 11
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1Delete old log files safely (spaces in names work)
2One command per item with {}
3Pull many images in parallel (4 at a time)
cat images.txt | xargs -P 4 -n 1 docker pull4Delete all Evicted pods
kubectl get pods -A --field-selector=status.phase=Failed -o jsonpath='{range .items[*]}{.metadata.namespace} {.metadata.name}{"\n"}{end}' | xargs -r -n 2 sh -c 'kubectl delete pod -n "$0" "$1"'5grep in the files that find found
6See the commands before they run
echo web1 web2 | xargs -t -n 1 ping -c 17Check many URLs fast
xargs -P 8 -I {} curl -s -o /dev/null -w '%{http_code} {}\n' {} < urls.txt8Remove merged Git branches
9Archive files in batches of 100
find data -type f -print0 | xargs -0 -n 100 tar -rf data.tar10Lines (not words) as items
11Ask before each delete
لا يوجد شيء يطابق هذا الفلتر.
انتبه
- Without
-0/-d '\n'xargs splits on spaces and quotes: "my file" becomes two items. - Without
-rGNU xargs runs the command once with no arguments when the input is empty — dangerous withrm. - Output of parallel runs (
-P) can mix; write each result to its own file if order matters.
نصائح للحفظ
find -exec cmd {} +does the same job asfind | xargsfor simple cases.
رموز الخروج
0 | All runs exited 0. |
123 | A run exited with 1–125. |
124 | A run exited with 255. |
125 | A run was killed by a signal. |
126 | The command cannot run. |
127 | The command was not found. |