{"id":462,"date":"2015-12-12T11:45:14","date_gmt":"2015-12-12T11:45:14","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2015\/12\/12\/20-xargs-commands-examples-in-linux-unix\/"},"modified":"2022-04-24T04:23:41","modified_gmt":"2022-04-24T04:23:41","slug":"20-xargs-commands-examples-in-linux-unix","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/20-xargs-commands-examples-in-linux-unix\/","title":{"rendered":"Linux Tutorials: xargs commands examples"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3174 size-full\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2015\/12\/xargs-commands-examples-in-.png\" alt=\"xargs-commands\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/12\/xargs-commands-examples-in-.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/12\/xargs-commands-examples-in--300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Under Development<\/p>\n<div><\/div>\n<div><\/div>\n<div>The xargs command is extremely useful when we combine it with other commands.This tutorials explains the usage of xargs command using few simple examples.<\/div>\n<div><\/div>\n<div>1. Xargs Basic Example<\/div>\n<div>The xargs command (by default) expects the input from stdin, and executes \/bin\/echo command over the input. When you execute xargs without any argument, or when you execute it without combining with any other commands. you get Welcome message<\/div>\n<div><\/div>\n<div>&gt; xargs<\/div>\n<div>Hi,<\/div>\n<div>Welcome to TGS.Hi, Welcome to TGS.<\/div>\n<div>After you type something, press ctrl+d, which will echo the string back to you on stdout as shown below.<\/div>\n<div><\/div>\n<div>2. Specify Delimiter Using -d option<\/div>\n<div>Delimiters can be applied so that each character in the input is taken literally using -d option in xargs.In the following example, when you use the -d\\n, it will preserve newline delimiter in the output, and display the output exactly as it was typed.<\/div>\n<div><\/div>\n<div>&gt; xargs -d\\n<\/div>\n<div>Hi,<\/div>\n<div>Welcome to TGS.<\/div>\n<div><\/div>\n<div>3. Limit Output Per Line Using -n Option<\/div>\n<div><\/div>\n<div>By default as explained earlier, xargs displays whatever comes to its stdin as shown below.<\/div>\n<div><\/div>\n<div>&gt; echo a b c d e f| xargs<\/div>\n<div>a b c d e f<\/div>\n<div><\/div>\n<div>&gt; echo a b c d e f| xargs -n 3<\/div>\n<div>a b c<\/div>\n<div>d e f<\/div>\n<div><\/div>\n<div>In the following example, we used -n 3, which will display only 3 items per line in the xargs output.<\/div>\n<div><\/div>\n<div>4. Delete Files that has White-space in the Filename<\/div>\n<div>&gt; find . -name &#8220;*.c&#8221; -print0 | xargs -0 rm -rf<\/div>\n<div><\/div>\n<div><\/div>\n<div>Example<\/div>\n<div># fild \/usr\/preserve \u2013mtime +30 \u2013exec rm \u2013f {} \\;<\/div>\n<div>is equivalent to&#8230;.<\/div>\n<div># find \/usr\/preserve \u2013mtime +30 \u2013print | xargs rm \u2013f<\/div>\n<div># find \/usr\/preserve \u2013size +1024 \u2013print | xargs \u2013n20 rm \u2013f<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Under Development The xargs command is extremely useful when we combine it with other commands.This tutorials explains the usage of xargs command using few simple examples. 1. Xargs Basic Example The xargs command (by default) expects the input from stdin, and executes \/bin\/echo command over the input. When you execute xargs without any argument, or&#8230;<\/p>\n","protected":false},"author":1,"featured_media":3174,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[4957],"tags":[378,632,460,1274,169,1271,1272,1273,1276,1275],"class_list":["post-462","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-commands","tag-examples","tag-linux","tag-linux-xargs-command","tag-unix","tag-xargs","tag-xargs-command","tag-xargs-command-examples","tag-xargs-command-line","tag-xargs-commands-tutorials"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=462"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/462\/revisions"}],"predecessor-version":[{"id":29692,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/462\/revisions\/29692"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/3174"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}