{"id":248442,"date":"2021-05-12T15:00:00","date_gmt":"2021-05-12T12:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-use-brace-expansion-in-linuxs-bash-shell\/"},"modified":"2021-05-12T15:00:00","modified_gmt":"2021-05-12T12:00:00","slug":"how-to-use-brace-expansion-in-linuxs-bash-shell","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-use-brace-expansion-in-linuxs-bash-shell\/","title":{"rendered":"#How to Use Brace Expansion in Linux\u2019s Bash Shell"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a24c162828f5\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a24c162828f5\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-brace-expansion-in-linuxs-bash-shell\/#Brace_Expansion\" >Brace Expansion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-brace-expansion-in-linuxs-bash-shell\/#Simple_Expansions\" >Simple Expansions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-brace-expansion-in-linuxs-bash-shell\/#Using_Brace_Expansion_with_Loops\" >Using Brace Expansion with Loops<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-brace-expansion-in-linuxs-bash-shell\/#Concatenating_and_Nesting\" >Concatenating and Nesting<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-brace-expansion-in-linuxs-bash-shell\/#Preamble_and_Postscript\" >Preamble and Postscript<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-brace-expansion-in-linuxs-bash-shell\/#Expanding_File_Names_and_Directories\" >Expanding File Names and Directories<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-brace-expansion-in-linuxs-bash-shell\/#Embrace_the_Brace\" >Embrace the Brace<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Use Brace Expansion in Linux\u2019s Bash Shell&#8221;<\/strong><\/p>\n<div>\n<figure style=\"width: 650px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage wp-image-442612 size-full\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2019\/09\/stock-lede-linux-see-attribution.png?width=1200&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A terminal window on a Linux system.\" width=\"650\" height=\"300\" data-credittext=\"Fatmawati Achmad Zaenuri\/Shutterstock\" data-crediturl=\"https:\/\/www.shutterstock.com\/image-vector\/linux-interface-screen-notebook-world-map-321627716\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\"><span class=\"type:primaryImage imagecredit\"><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.shutterstock.com\/image-vector\/linux-interface-screen-notebook-world-map-321627716\">Fatmawati Achmad Zaenuri\/Shutterstock<\/a><\/span><\/figcaption><\/figure>\n<p>Brace expansion is a useful technique to generate lists of strings that can be used in <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">script<\/a>s and aliases and on the Linux command line. Save time and avoid mistakes by typing less.<\/p>\n<h2 id=\"brace-expansion\"><span class=\"ez-toc-section\" id=\"Brace_Expansion\"><\/span>Brace Expansion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before the Bash shell <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/man7.org\/linux\/man-pages\/man1\/bash.1.html\">executes a command<\/a> in a terminal window or a line in a script, it checks whether it needs to perform any substitutions on the command. Variable names are replaced by their values, aliases are replaced by the commands they\u2019re shorthand for, and any expansion is performed. Brace expansion is one form of expansion supported by Bash.<\/p>\n<p>Brace expansion is available in modern shells, but it might be missing from some old shells. If you\u2019re going to use brace expansion in scripts, make sure that you invoke a shell that supports brace expansion, such as Bash:<\/p>\n<p>We\u2019ll be using Bash for our examples.<\/p>\n<p>Generating lists of strings might seem more of a novelty than a benefit, but it does offer some functionality that can save time and keystrokes. Often, it can provide a simple and elegant solution to a problem or requirement.<\/p>\n<h2 id=\"simple-expansions\"><span class=\"ez-toc-section\" id=\"Simple_Expansions\"><\/span>Simple Expansions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A brace expansion is contained between a pair of braces \u201c{}\u201d. It can be a list of comma-separated items or a range specifier. Spaces are not permitted inside the braces unless you\u2019ve wrapped the string in quotation marks \u201c<code>\"<\/code>.\u201d<\/p>\n<p>For a comma-separated list, the expansion process takes each element in turn and passes it to the calling command. In this example, it\u2019s <code>echo<\/code>\u00a0that simply prints them in the terminal window. Note that the commas are ignored.<\/p>\n<pre>echo {one,two,three,four}<\/pre>\n<p>A list can be words or digits.<\/p>\n<pre>echo {1,2,3,4}<\/pre>\n<p>The order of the list elements is completely arbitrary.<\/p>\n<pre>echo (4,2,3,1)<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725667\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/2-3.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"165\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>An expansion range has a start and an end character connected with two periods \u201d <code>..<\/code> \u201d without any whitespace. All of the missing list elements are provided automatically by the expansion so that the entire range from start character to end character is created.<\/p>\n<p>This will print the digits from 1 to 10.<\/p>\n<pre>echo {1..10}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725672\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/3-2.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The numbering is arbitrary. It does not have to start at one.<\/p>\n<pre>echo {3..12}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725674\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/4-3.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Ranges can be specified so that they run backward. This will generate a list from five down to one.<\/p>\n<pre>echo {5..1}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725676\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/5-1.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Ranges can include negative numbers.<\/p>\n<pre>echo {4..-4}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725679\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/6-2.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>As we previously pointed out, a range has a start and an end <em>character<\/em>. It doesn\u2019t have to be a number. It can be a letter.<\/p>\n<pre>echo {q..v}<\/pre>\n<p>The letters can run backward, too.<\/p>\n<pre>echo {f..a}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725689\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/7-3.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"130\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<h2 id=\"using-expansion-with-variables-in-loops\"><span class=\"ez-toc-section\" id=\"Using_Brace_Expansion_with_Loops\"><\/span>Using Brace Expansion with Loops<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can use brace expansion with ranges in loops in scripts.<\/p>\n<pre>for i in {3..7}&#13;\ndo&#13;\n   echo $i&#13;\ndone<\/pre>\n<p>Brace expansion ranges let you use characters as the loop variable.<\/p>\n<pre>for i in {m..q}&#13;\ndo&#13;\n   echo $i&#13;\ndone<\/pre>\n<p>Loops are usually used in scripts, but there\u2019s nothing to stop you from typing them into the command line to see what will happen.<\/p>\n<pre>for i in {3..7}; do echo $i; done<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725699\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/8-3.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"645\" height=\"160\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<pre>for i in {m..q}; do echo $i; done<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725700\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/9-3.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"160\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<h2 id=\"concatenating-and-nesting-expansion\"><span class=\"ez-toc-section\" id=\"Concatenating_and_Nesting\"><\/span>Concatenating and Nesting<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Two adjacent expansions don\u2019t act independently one after the other. They interoperate. Each element in the first expansion is acted on by each element in the second expansion.<\/p>\n<pre>echo {q..v}{1..3}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725729\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/10-1.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Expansions can also be nested. A nested expansion will act on the element im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>tely preceding it.<\/p>\n<pre>echo {part-1,part-2{a,b,c,d},part-3}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-725957 size-full\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/24.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can also nest expansions by creating a comma-delimited list of range expansions.<\/p>\n<pre>echo {{5..0},{1..5}}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725733\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/15-2.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<h2 id=\"preamble-and-postscript\"><span class=\"ez-toc-section\" id=\"Preamble_and_Postscript\"><\/span>Preamble and Postscript<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can place text before and after a brace expansion to have that text included in the results of the expansion. Text put in front of an expansion is called the preamble, while text placed behind a brace expansion is called the postscript.<\/p>\n<p>This command uses a preamble.<\/p>\n<pre>echo chapter{1..3}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725735\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/12-2.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This example uses a postscript:<\/p>\n<pre>echo {contents,paper,bilbiography}.md<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725736\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/13-2.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>And this command uses both.<\/p>\n<pre>echo chapter-{1..4}.md<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725737\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/14-2.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"645\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<h2 id=\"expanding-file-names\"><span class=\"ez-toc-section\" id=\"Expanding_File_Names_and_Directories\"><\/span>Expanding File Names and Directories<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>As you\u2019ve probably guessed by now, one of the main uses of brace expansions is to create file and directory names that can be passed to other commands. We\u2019ve been using <code>echo<\/code> as a convenient way to see exactly what happens when an expansion is triggered. You can substitute any command that takes filenames or directory names as input and use brace expansion with it.<\/p>\n<p>To quickly create some files, use <code>touch<\/code>:<\/p>\n<pre>touch file-{1..4}.txt<\/pre>\n<pre>ls *.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725806\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/17-1.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"120\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you have many files with the same base name but different file extensions and you want to perform an operation on a subset of them, brace expansions can help. Here, we\u2019re compressing a subset of files that have \u201cprogram\u201d as the basename into a ZIP file called \u201csource-code.zip.\u201d<\/p>\n<p>Development directories contain lots of files that will have the same basename as your main program. Usually, you don\u2019t want to back up or distribute files like \u201c.o\u201d object files. This is a neat way to only include the file types of interest.<\/p>\n<pre>zip source-code program{.c,.h,.css}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725808\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/18.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"130\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This command will make a copy of a file and append \u201c.bak\u201d to it, making a backup copy of the original file. An interesting point to note is that the brace expansion contains a comma-separated list, but the first element is empty. If we hadn\u2019t included the comma, the expansion wouldn\u2019t have taken place.<\/p>\n<pre>cp brace\/new\/prog-1.c{,.bak}<\/pre>\n<pre>ls brace\/new\/prog-1.c.bak<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725846\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/20-1.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"120\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>To perform some action on two files in different directories, we can use a brace expansion in the path to the files.<\/p>\n<p>In this example, the \u201cbrace\u201d directory contains two subdirectories, one called \u201cnew\u201d and one called \u201cold.\u201d They contain different versions of the same set of source code files. We\u2019ll use the <code>diff<\/code> program to see the differences between the two versions of \u201cprog-1.c.\u201d<\/p>\n<pre>diff brace\/{new,old}\/prog-1.c<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725847\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/19-1.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"130\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you have a standard skeleton of directories that you need to create at the start of a project, you can create them quickly using brace expansion. The\u00a0 <code>mkdir<\/code> <code>-p<\/code> (parent) option <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/man7.org\/linux\/man-pages\/man1\/mkdir.1.html\">creates any missing parent directories<\/a> when a child directory is created.<\/p>\n<pre>mkdir -p {source,build,man,help{\/pages,\/yelp,\/images}}<\/pre>\n<pre>tree<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725850\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/21-1.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"290\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can use brace expansion with\u00a0<code>wget<\/code> to <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/man7.org\/linux\/man-pages\/man1\/wget.1.html\">download multiple files<\/a>.<\/p>\n<p>In this command, we\u2019re going to download files from two directories, called \u201ctest1\u201d and \u201ctest2.\u201d Each directory holds two files called \u201cpicture1\u201d and \u201cpicture2.\u201d<\/p>\n<pre>wget https:\/\/www.URL-of-your-choice.com\/test{1,2}\/picture{001,002}.jpg<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725934\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/22.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"75\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Listing the files shows you the files that were retrieved and how <code>wget<\/code>\u00a0renames files to avoid name clashes with existing files.<\/p>\n<pre>ls picture*.*<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-725935\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/04\/23.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"644\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Embrace_the_Brace\"><\/span>Embrace the Brace<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>It seems that brace expansion is another one of Linux\u2019s best-kept secrets. Many people tell me that they\u2019ve never heard of brace expansion, while others inform me that it\u2019s one of their favorite command-line tricks.<br \/>\nGive it a try and it just might find its way into your set of command-line go-to tricks.<\/p>\n<\/div>\n<p><script>\n setTimeout(function(){\n  !function(f,b,e,v,n,t,s)\n  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n  n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n  n.queue=[];t=b.createElement(e);t.async=!0;\n  t.src=v;s=b.getElementsByTagName(e)[0];\n  s.parentNode.insertBefore(t,s) } (window, document,'script',\n  'https:\/\/connect.facebook.net\/en_US\/fbevents.js');\n   fbq('init', '335401813750447');\n   fbq('track', 'PageView');\n  },3000);\n<\/script><\/p>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.howtogeek.com\/725657\/how-to-use-brace-expansion-in-linuxs-bash-shell\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Use Brace Expansion in Linux\u2019s Bash Shell&#8221; Fatmawati Achmad Zaenuri\/Shutterstock Brace expansion is a useful technique to generate lists of strings that can be used in scripts and aliases and on the Linux command line. Save time and avoid mistakes by typing less. Brace Expansion Before the Bash shell executes a command in&#8230;<\/p>\n","protected":false},"author":1,"featured_media":248443,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2019\/09\/stock-lede-linux-see-attribution.png?height=200p&trim=2,2,2,2","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-248442","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/248442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=248442"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/248442\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/248443"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=248442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=248442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=248442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}