Difference between revisions of "Linux command: xargs"

From RHS Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
  ls | xargs -t rm -r # -t shows the command that will be executed
 
  ls | xargs -t rm -r # -t shows the command that will be executed
 
  ls | xargs -t -n1 rm -r # Limit to one the number of arguments passed to rm
 
  ls | xargs -t -n1 rm -r # Limit to one the number of arguments passed to rm
 +
echo "pdgrt-api-central  pdgrt-api-node  pdgrt-deployment  rt-central  rt-node" | xargs -n1  | xargs -I  ARG git clone git@git.rra.lan:PDGRT_2.0/ARG.git
 
</source>
 
</source>
  

Latest revision as of 08:36, 31 May 2018

Examples:

 ls | xargs rm -rf # Delete all elements inside current directory
 ls | xargs -t rm -r # -t shows the command that will be executed
 ls | xargs -t -n1 rm -r # Limit to one the number of arguments passed to rm
 echo "pdgrt-api-central  pdgrt-api-node  pdgrt-deployment  rt-central  rt-node" | xargs -n1  | xargs -I  ARG git clone git@git.rra.lan:PDGRT_2.0/ARG.git

Other arguments
-P Specify max number of parallel processes
-I Specify argument possition ej: ls | xargs -I ARG echo before ARG after


 mkdir directory_{000..999}
 ls
 ls | xargs -t -n10 rm -rf