{"id":18605,"date":"2022-03-12T10:49:03","date_gmt":"2022-03-12T09:49:03","guid":{"rendered":"https:\/\/daniel.haxx.se\/blog\/?p=18605"},"modified":"2022-03-12T10:49:03","modified_gmt":"2022-03-12T09:49:03","slug":"curl-no-clobber","status":"publish","type":"post","link":"https:\/\/daniel.haxx.se\/blog\/2022\/03\/12\/curl-no-clobber\/","title":{"rendered":"curl no clobber"},"content":{"rendered":"\n<p>Do you remember August 26 2002? I can&#8217;t say I particularly do but the curl git log remembers for us that it was on that day <a href=\"https:\/\/github.com\/curl\/curl\/commit\/87c43517cd\">we added this TODO item<\/a>:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Add an option that prevents cURL from overwriting existing local files. When used, and there already is an existing file with the target file name (either -O or -o), a number should be appended (and increased if already existing).<\/p><\/blockquote>\n\n\n\n<p>That idea hadn&#8217;t even been listed for twenty years before it was converted into code by <a href=\"https:\/\/github.com\/Hex052\">HexTheDragon<\/a> and landed in curl the other day (with <a href=\"https:\/\/github.com\/curl\/curl\/commit\/1831a6e7f179165c3c2055dd00f68bc5e9d27240\">this commit<\/a>). To get included in the pending curl 7.83.0 release.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>--no-clobber<\/code><\/h2>\n\n\n\n<p>This new command line option (curl&#8217;s 247th) is called <code><a href=\"https:\/\/curl.se\/docs\/manpage.html#--no-clobber\">--no-clobber<\/a><\/code> and it works as suggested already back in 2002. If the output file already exists at the time when curl wants to create it, it will instead append a number to the end of the name. If that file <em>also<\/em> exists, curl retries iteratively with numbers up to a 100 before it gives up and returns error.<\/p>\n\n\n\n<p>To help you write even cooler scripts. Oh, and the <code>-w<\/code> variable <code><a href=\"https:\/\/everything.curl.dev\/usingcurl\/verbose\/writeout\">%{filename_effective}<\/a><\/code> will show this actually used file name.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do you remember August 26 2002? I can&#8217;t say I particularly do but the curl git log remembers for us that it was on that day we added this TODO item: Add an option that prevents cURL from overwriting existing local files. When used, and there already is an existing file with the target file &hellip; <a href=\"https:\/\/daniel.haxx.se\/blog\/2022\/03\/12\/curl-no-clobber\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">curl no clobber<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":5,"featured_media":13469,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[214,33],"class_list":["post-18605","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-curl","tag-command-line","tag-curl-and-libcurl"],"_links":{"self":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/18605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/comments?post=18605"}],"version-history":[{"count":13,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/18605\/revisions"}],"predecessor-version":[{"id":18633,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/18605\/revisions\/18633"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media\/13469"}],"wp:attachment":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media?parent=18605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/categories?post=18605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/tags?post=18605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}