{"id":2919,"date":"2012-01-25T14:46:50","date_gmt":"2012-01-25T14:46:50","guid":{"rendered":""},"modified":"2014-07-05T05:24:49","modified_gmt":"2014-07-05T05:24:49","slug":"argument-list-too-long","status":"publish","type":"post","link":"https:\/\/www.munmon.com\/v3\/2012\/01\/25\/argument-list-too-long\/","title":{"rendered":"Argument list too long"},"content":{"rendered":"<p>Any of you encountered &#8220;Argument list too long&#8221; problem when trying to mass delete files in a folder? Today I want to erase more than a million files in a folder. So I ran &#8220;rm -rf *.jpg&#8221; and the &#8220;Argument list too long&#8221; error was returned. What the hell???<\/p>\n<p>So I quickly google this Argument bla bla bla thinggy.<\/p>\n<p>This is what I understand so far:<\/p>\n<p>The reason for this annoyance is that Linux kernel has a limitation of bytes it can process through as arguments in exec() commands. [http:\/\/netweblogic.com\/linux\/linux-commands-argument-list-too-long\/]<\/p>\n<blockquote>\n<p>The system could not handle the number of arguments given to a command or program when it combined those arguments with the environment&#8217;s exported shell variables. The argument list limit is the size of the argument list plus the size of the environment&#8217;s exported shell variables.<\/p>\n<p>The easiest solution is to reduce the size of the parent process environment by unsetting extraneous environment variables. (See the man page for the shell you&#8217;re using to find out how to list and change your environment variables.) Then run the program again.<\/p>\n<p>An argument list longer than ARG_MAX bytes was presented to a member of the exec() family of system calls.<\/p>\n<\/blockquote>\n<p>Moral of the story: Everythings has its own limitation. \ud83d\ude09<\/p>\n<p>How to solve this?<\/p>\n<p>According to Alessandre S. Naro in <a href=\"http:\/\/www.linuxjournal.com\/article\/6060\">&#8220;Argument list too long&#8221;: Beyond Arguments and Limitations<\/a>, he points out 4 ways to overcome this problem.<\/p>\n<p>Method #1: Manually split the command line arguments into smaller bunches.<br \/>Method #2: Use the find command.<br \/>Method #3: Create a function. and<br \/>Method #4: Recompile the Linux kernel.<\/p>\n<p>So I choose method #2. Easier and faster. You can run this in single command. Example:<\/p>\n<p>find \/opt\/library\/images\/bookcovers_tiny\/ -name &#8216;*.jpg&#8217; -print0 | xargs -0 rm -f<\/p>\n<p>Done. All files deleted. Yeay!!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Any of you encountered &#8220;Argument list too long&#8221; problem when trying to mass delete files in a folder? Today I want to erase more than a million files in a folder. So I ran &#8220;rm -rf *.jpg&#8221; and the &#8220;Argument list too long&#8221; error was returned. What the hell???<\/p>\n<p>So I quickly google this Argument bla bla bla thinggy.<\/p>\n<p>This is what I understand so far:<\/p>\n<p>The reason for this annoyance is that Linux kernel has a limitation of bytes it can process through as arguments in exec() commands. [http:\/\/netweblogic.com\/linux\/linux-commands-argument-list-too-long\/]<\/p>\n<blockquote>\n<p>The system could not handle the number of arguments given to a command or program when it combined those arguments with the environment&#8217;s exported shell variables. The argument list limit is the size of the argument list plus the size of the environment&#8217;s exported shell variables.<\/p>\n<p>The easiest solution is to reduce the size of the parent process environment by unsetting extraneous environment variables. (See the man page for the shell you&#8217;re using to find out how to list and change your environment variables.) Then run the program again.<\/p>\n<p>An argument list longer than ARG_MAX bytes was presented to a member of the exec() family of system calls.<\/p>\n<\/blockquote>\n<p>Moral of the story: Everythings has its own limitation. \ud83d\ude09<\/p>\n<p>How to solve this?<\/p>\n<p>According to Alessandre S. Naro in <a href=\"http:\/\/www.linuxjournal.com\/article\/6060\">&#8220;Argument list too long&#8221;: Beyond Arguments and Limitations<\/a>, he points out 4 ways to overcome this problem.<\/p>\n<p>Method #1: Manually split the command line arguments into smaller bunches.<br \/>Method #2: Use the find command.<br \/>Method #3: Create a function. and<br \/>Method #4: Recompile the Linux kernel.<\/p>\n<p>So I choose method #2. Easier and faster. You can run this in single command. Example:<\/p>\n<p>find \/opt\/library\/images\/bookcovers_tiny\/ -name &#8216;*.jpg&#8217; -print0 | xargs -0 rm -f<\/p>\n<p>Done. All files deleted. Yeay!!<\/p>\n<p>&nbsp;<\/p>\n<p>&hellip;  <\/p>\n<p class=\"more-link\"><a href=\"https:\/\/www.munmon.com\/v3\/2012\/01\/25\/argument-list-too-long\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wp_rev_ctl_limit":""},"categories":[155],"tags":[114,115,39],"class_list":["post-2919","post","type-post","status-publish","format-standard","hentry","category-munmonlisme","tag-bash","tag-cli","tag-linux"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4NeyD-L5","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.munmon.com\/v3\/wp-json\/wp\/v2\/posts\/2919","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.munmon.com\/v3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.munmon.com\/v3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.munmon.com\/v3\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.munmon.com\/v3\/wp-json\/wp\/v2\/comments?post=2919"}],"version-history":[{"count":0,"href":"https:\/\/www.munmon.com\/v3\/wp-json\/wp\/v2\/posts\/2919\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.munmon.com\/v3\/wp-json\/wp\/v2\/media?parent=2919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.munmon.com\/v3\/wp-json\/wp\/v2\/categories?post=2919"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.munmon.com\/v3\/wp-json\/wp\/v2\/tags?post=2919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}