{"id":1370,"date":"2019-05-04T14:49:47","date_gmt":"2019-05-04T19:49:47","guid":{"rendered":"http:\/\/russellstinnett.com\/?p=1370"},"modified":"2019-05-04T14:49:47","modified_gmt":"2019-05-04T19:49:47","slug":"how-to-rename-similar-files-at-the-command-prompt-using-sed","status":"publish","type":"post","link":"https:\/\/russellstinnett.com\/?p=1370","title":{"rendered":"How to Rename Similar Files at the Command Prompt Using Sed"},"content":{"rendered":"\n<p>Using a simple &#8220;script&#8221; at the command line, you can rename a bunch of similar filenames with ease. Say you&#8217;ve got something like: foo-001, foo-002 and foo-003, but you want them to be bar-001, bar-002 and bar-003. The script will look like : <br>\n<code>$ for i in `ls -1 foo*`; do mv $i `echo $i |sed -e 's\/foo\/bar\/'`; done<\/code><br>\nYou can test your code without making changes by removing the &#8216;mv&#8217; command and just echoing the results to stdout like so :<br>\n<code>$ for i in `ls -1 foo*'; do echo $i |sed -e 's\/foo\/bar\/'; done<\/code><br>\nWith the latter command, you can examine the results to see if that&#8217;s actually what you want &#8216;mv&#8217; to rename the files to.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using a simple &#8220;script&#8221; at the command line, you can rename a bunch of similar filenames with ease. Say you&#8217;ve got something like: foo-001, foo-002 and foo-003, but you want them to be bar-001, bar-002 and bar-003. The script will look like : $ for i in `ls -1 foo*`; do mv $i `echo $i&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,1],"tags":[52,70,75],"class_list":["post-1370","post","type-post","status-publish","format-standard","hentry","category-linux","category-uncategorized","tag-linux","tag-rename","tag-sed"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Rename Similar Files at the Command Prompt Using Sed - A Commonplace Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/russellstinnett.com\/?p=1370\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Rename Similar Files at the Command Prompt Using Sed - A Commonplace Blog\" \/>\n<meta property=\"og:description\" content=\"Using a simple &#8220;script&#8221; at the command line, you can rename a bunch of similar filenames with ease. Say you&#8217;ve got something like: foo-001, foo-002 and foo-003, but you want them to be bar-001, bar-002 and bar-003. The script will look like : $ for i in `ls -1 foo*`; do mv $i `echo $i...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/russellstinnett.com\/?p=1370\" \/>\n<meta property=\"og:site_name\" content=\"A Commonplace Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-04T19:49:47+00:00\" \/>\n<meta name=\"author\" content=\"russell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"russell\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/russellstinnett.com\\\/?p=1370#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/russellstinnett.com\\\/?p=1370\"},\"author\":{\"name\":\"russell\",\"@id\":\"https:\\\/\\\/russellstinnett.com\\\/#\\\/schema\\\/person\\\/056f15a8cb83837a561f105dc1475ce8\"},\"headline\":\"How to Rename Similar Files at the Command Prompt Using Sed\",\"datePublished\":\"2019-05-04T19:49:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/russellstinnett.com\\\/?p=1370\"},\"wordCount\":100,\"keywords\":[\"linux\",\"rename\",\"sed\"],\"articleSection\":[\"Linux\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/russellstinnett.com\\\/?p=1370\",\"url\":\"https:\\\/\\\/russellstinnett.com\\\/?p=1370\",\"name\":\"How to Rename Similar Files at the Command Prompt Using Sed - A Commonplace Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/russellstinnett.com\\\/#website\"},\"datePublished\":\"2019-05-04T19:49:47+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/russellstinnett.com\\\/#\\\/schema\\\/person\\\/056f15a8cb83837a561f105dc1475ce8\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/russellstinnett.com\\\/?p=1370#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/russellstinnett.com\\\/?p=1370\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/russellstinnett.com\\\/?p=1370#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/russellstinnett.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Rename Similar Files at the Command Prompt Using Sed\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/russellstinnett.com\\\/#website\",\"url\":\"https:\\\/\\\/russellstinnett.com\\\/\",\"name\":\"A Commonplace Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/russellstinnett.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/russellstinnett.com\\\/#\\\/schema\\\/person\\\/056f15a8cb83837a561f105dc1475ce8\",\"name\":\"russell\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b1fb12238c00e45c4820005d8619303e4635df76f75ef14a958d79ef08e2ce00?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b1fb12238c00e45c4820005d8619303e4635df76f75ef14a958d79ef08e2ce00?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b1fb12238c00e45c4820005d8619303e4635df76f75ef14a958d79ef08e2ce00?s=96&d=mm&r=g\",\"caption\":\"russell\"},\"sameAs\":[\"https:\\\/\\\/russellstinnett.com\"],\"url\":\"https:\\\/\\\/russellstinnett.com\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Rename Similar Files at the Command Prompt Using Sed - A Commonplace Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/russellstinnett.com\/?p=1370","og_locale":"en_US","og_type":"article","og_title":"How to Rename Similar Files at the Command Prompt Using Sed - A Commonplace Blog","og_description":"Using a simple &#8220;script&#8221; at the command line, you can rename a bunch of similar filenames with ease. Say you&#8217;ve got something like: foo-001, foo-002 and foo-003, but you want them to be bar-001, bar-002 and bar-003. The script will look like : $ for i in `ls -1 foo*`; do mv $i `echo $i...","og_url":"https:\/\/russellstinnett.com\/?p=1370","og_site_name":"A Commonplace Blog","article_published_time":"2019-05-04T19:49:47+00:00","author":"russell","twitter_card":"summary_large_image","twitter_misc":{"Written by":"russell","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/russellstinnett.com\/?p=1370#article","isPartOf":{"@id":"https:\/\/russellstinnett.com\/?p=1370"},"author":{"name":"russell","@id":"https:\/\/russellstinnett.com\/#\/schema\/person\/056f15a8cb83837a561f105dc1475ce8"},"headline":"How to Rename Similar Files at the Command Prompt Using Sed","datePublished":"2019-05-04T19:49:47+00:00","mainEntityOfPage":{"@id":"https:\/\/russellstinnett.com\/?p=1370"},"wordCount":100,"keywords":["linux","rename","sed"],"articleSection":["Linux"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/russellstinnett.com\/?p=1370","url":"https:\/\/russellstinnett.com\/?p=1370","name":"How to Rename Similar Files at the Command Prompt Using Sed - A Commonplace Blog","isPartOf":{"@id":"https:\/\/russellstinnett.com\/#website"},"datePublished":"2019-05-04T19:49:47+00:00","author":{"@id":"https:\/\/russellstinnett.com\/#\/schema\/person\/056f15a8cb83837a561f105dc1475ce8"},"breadcrumb":{"@id":"https:\/\/russellstinnett.com\/?p=1370#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/russellstinnett.com\/?p=1370"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/russellstinnett.com\/?p=1370#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/russellstinnett.com\/"},{"@type":"ListItem","position":2,"name":"How to Rename Similar Files at the Command Prompt Using Sed"}]},{"@type":"WebSite","@id":"https:\/\/russellstinnett.com\/#website","url":"https:\/\/russellstinnett.com\/","name":"A Commonplace Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/russellstinnett.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/russellstinnett.com\/#\/schema\/person\/056f15a8cb83837a561f105dc1475ce8","name":"russell","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b1fb12238c00e45c4820005d8619303e4635df76f75ef14a958d79ef08e2ce00?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b1fb12238c00e45c4820005d8619303e4635df76f75ef14a958d79ef08e2ce00?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b1fb12238c00e45c4820005d8619303e4635df76f75ef14a958d79ef08e2ce00?s=96&d=mm&r=g","caption":"russell"},"sameAs":["https:\/\/russellstinnett.com"],"url":"https:\/\/russellstinnett.com\/?author=1"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/russellstinnett.com\/index.php?rest_route=\/wp\/v2\/posts\/1370","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/russellstinnett.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/russellstinnett.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/russellstinnett.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/russellstinnett.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1370"}],"version-history":[{"count":0,"href":"https:\/\/russellstinnett.com\/index.php?rest_route=\/wp\/v2\/posts\/1370\/revisions"}],"wp:attachment":[{"href":"https:\/\/russellstinnett.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/russellstinnett.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/russellstinnett.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}