{"id":462476,"date":"2022-06-13T20:00:02","date_gmt":"2022-06-13T17:00:02","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-rename-a-directory-on-linux\/"},"modified":"2022-06-13T20:00:02","modified_gmt":"2022-06-13T17:00:02","slug":"how-to-rename-a-directory-on-linux","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-rename-a-directory-on-linux\/","title":{"rendered":"#How to Rename a Directory on Linux"},"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-6a2f2efe55fa2\" 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-6a2f2efe55fa2\" 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-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-rename-a-directory-on-linux\/#%E2%80%9CHow_to_Rename_a_Directory_on_Linux%E2%80%9D\" >&#8220;How to Rename a Directory on Linux&#8221;<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-rename-a-directory-on-linux\/#Your_Data_Is_Safe\" >Your Data Is Safe<\/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-rename-a-directory-on-linux\/#Using_the_mv_Command\" >Using the mv Command<\/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-rename-a-directory-on-linux\/#Using_the_File_Browser\" >Using the File Browser<\/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-rename-a-directory-on-linux\/#The_rename_Command\" >The rename Command<\/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-rename-a-directory-on-linux\/#First_Steps_With_rename\" >First Steps With rename<\/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-rename-a-directory-on-linux\/#Using_rename_With_Other_Commands\" >Using rename With Other Commands<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-rename-a-directory-on-linux\/#Horses_for_Courses\" >Horses for Courses<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E2%80%9CHow_to_Rename_a_Directory_on_Linux%E2%80%9D\"><\/span>&#8220;How to Rename a Directory on Linux&#8221;<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<div>\n<figure style=\"width: 1200px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage size-full wp-image-791996\" data-pagespeed-no-defer=\"\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/03\/shutterstock_321627716.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Linux laptop showing a bash prompt\" width=\"1200\" height=\"675\"\/><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.com<\/a><\/span><\/figcaption><\/figure>\n<p>Renaming a directory in Linux is easy, and there are plenty of ways to go about it. From renaming a single directory to finding and renaming many, here\u2019s how to do it.<\/p>\n<h2 id=\"your-data-is-safe\"><span class=\"ez-toc-section\" id=\"Your_Data_Is_Safe\"><\/span>Your Data Is Safe<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Renaming directories is something we all need to do from time to time.<\/p>\n<p>We might create a directory and misspell its name, and we want to put it right. Often, the purpose of a directory changes over time or through the life of a project, and you want to adjust the name to reflect its new use.\u00a0Perhaps you\u2019ve decompressed an archive file and it\u2019s created a directory tree with the directory names in uppercase and you\u2019d like them in lowercase.<\/p>\n<p>Whatever the reason. renaming a directory doesn\u2019t do anything to the data held inside it. It changes the <em>path<\/em> to that data, but the files and directories inside your renamed directory aren\u2019t touched.<\/p>\n<p>Don\u2019t rename system directories. Changing the path to system files and commands is going to have a detrimental effect on the running of your computer, to say the least. If you need to use <code>sudo<\/code> to rename a directory\u2014unless you really know what you\u2019re doing\u2014the chances are you shouldn\u2019t be renaming it.<\/p>\n<h2 id=\"using-the-mv-command\"><span class=\"ez-toc-section\" id=\"Using_the_mv_Command\"><\/span>Using the mv Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In the most straightforward cases, all we really need is the <code>mv<\/code> command. This is an integral part of every Linux distribution, so there is nothing to install.<\/p>\n<p>The <code>mv<\/code> command is over 50 years old at the time of writing. It hails from the dawn of Unix, when short and cryptic commands were in vogue, probably to reduce the number of characters that had to pass along slow serial lines from teletypes and dumb terminals to the actual computer.<\/p>\n<p>It actually stands for \u201cmove\u201d, and it can be used to move files from directory to directory. If you move a file to the same location that it is already in and give it a new name, you\u2019ve renamed the file. And we can do the same with directories.<\/p>\n<p>There are two subdirectories in this directory.<\/p>\n<pre>ls<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-807993\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/5-8.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Listing two subdirectories\" width=\"644\" height=\"95\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>To rename a directory we use the mv command. We need to provide the current name of the directory and the new name.<\/p>\n<pre>mv old-work archive-2<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-807995\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/6-8.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Renaming a directory with mv\" width=\"644\" height=\"55\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If the directory you want to rename is not in your current directory, provide the path as well as the directory name.<\/p>\n<pre>mv ~\/htg\/old-work ~\/htg\/archive-2<\/pre>\n<pre>ls<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-807996\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/7-8.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Renaming a directory in a different directory with mv by specifying the path on the command line\" width=\"644\" height=\"110\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<h2 id=\"using-the-file-browser\"><span class=\"ez-toc-section\" id=\"Using_the_File_Browser\"><\/span>Using the File Browser<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>File browsers are able to rename directories. The keystroke in the GNOME Files <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\">app<\/a>lication is F2. Highlighting a directory and tapping the F2 key opens the \u201cRename Folder\u201d dialog.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-807997\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/8-7.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using the fie browser to rename a directory\" width=\"644\" height=\"350\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Type in the new name, and click the green \u201cRename\u201d button.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808003\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/9-8.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Providing the new directory name in the file browser \" width=\"644\" height=\"350\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The directory is renamed for you.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808004\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/10-8.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"The renamed directory in the file browser window\" width=\"644\" height=\"240\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>It\u2019s as simple as that.<\/p>\n<h2 id=\"the-rename-command\"><span class=\"ez-toc-section\" id=\"The_rename_Command\"><\/span>The rename Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If your needs are more complicated than the straightforward renaming of a directory you might need to use the <code>rename<\/code> command. This allows you to use Perl expressions to rename files and directories. It provides an altogether more powerful and flexible way to rename directories.<\/p>\n<p>We\u2019re going to be talking about the Perl-based <code>rename<\/code> command. There is another, older command called <code>rename<\/code>\u00a0which is part of the Linux core utilities. You\u2019ll probably need to install the Perl <code>rename<\/code> command we want to use.<\/p>\n<p>To avoid name clashes with the existing <code>rename<\/code> command, the Perl <code>rename<\/code> command is called <code>prename<\/code> on Fedora, and <code>perl-rename<\/code> on Manjaro. On Ubuntu, the <code>rename<\/code> and <code>prename<\/code> commands are both symbolic links that resolve to a binary called <code>file-rename<\/code>.<\/p>\n<p>So, on Manjaro the command you\u2019ll need to use <code>perl-rename<\/code>, and on Fedora it is <code>prename<\/code> . On Ubuntu, you can use <code>rename<\/code> or <code>prename<\/code>.<\/p>\n<p>To install Perl rename, on Ubuntu you need to type:<\/p>\n<pre>sudo apt install rename<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808010\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/1-9.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Installing rename on Ubuntu\" width=\"644\" height=\"55\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>On Fedora, the command is:<\/p>\n<pre>sudo dnf install prename<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808012\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/3-8.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Installing prename on Fedora\" width=\"644\" height=\"55\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>On Manjaro the package is called <code>perl-rename<\/code>.<\/p>\n<pre>sudo pacman -Sy perl-rename<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808013\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/4-8.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Installing perl-rename on Manjaro\" width=\"644\" height=\"55\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Make sure you use the appropriate command for your distribution if you want to work through the examples.<\/p>\n<h2 id=\"first-steps-with-rename\"><span class=\"ez-toc-section\" id=\"First_Steps_With_rename\"><\/span>First Steps With rename<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>rename<\/code> command takes Perl regular expressions and applies them to a file or directory, or group of files or directories.<\/p>\n<p>In our directory, we have a collection of other directories.<\/p>\n<pre>ls<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808014\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/11-9.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A collection of directories in a mixture of uppercase, lowercase, and mixed case\" width=\"644\" height=\"95\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Their names are a mixture of lowercase, uppercase, and mixed case. We can convert them all to lowercase with a suitable expression.<\/p>\n<pre>rename 'y\/A-Z\/a-z\/' *<\/pre>\n<pre>ls<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808016\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/12-7.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Converting directories to lowercase names\" width=\"644\" height=\"110\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>All the directories are now in lowercase, whether they were wholly uppercase previously, or contained the odd uppercase letter.<\/p>\n<p>All the magic is contained in the expression. The expression is wrapped in single quotes \u201c<code>'<\/code>\u201c. This is what the entire command means.<\/p>\n<ul>\n<li><strong>y<\/strong>: This means search for any character in the first range of characters, and substitute it for the corresponding character from the second range of characters.<\/li>\n<li><strong>\/A-Z\/a-z\/<\/strong>: The first range is all the letters from \u201cA\u201d to \u201cZ\u201d, and the second range is all the characters from \u201ca\u201d to \u201cz.\u201d<\/li>\n<li><strong>*<\/strong>: The asterisk wildcard means apply this to all directories.<\/li>\n<\/ul>\n<p>In other words, the command reads as \u201cfor all directories, swap any uppercase letters for the equivalent lowercase letter.\u201d<\/p>\n<p>Obviously, you can rename a single directory with <code>rename<\/code>, although it does smack of overkill. You\u2019ll be quicker using <code>mv<\/code>.<\/p>\n<pre>rename 's\/gamma\/epsilon-2\/' *<\/pre>\n<pre>ls<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808018\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/13-7.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"renaming a single directory with rename\" width=\"644\" height=\"110\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The \u201cs\u201d in this expression means substitute. It checks each directory to see if its name is \u201cgamma\u201d. If it is, it replaces it with \u201cepsilon-2.\u201d Be aware though, that this would also have matched a directory called \u201cgamma-zeta\u201d, for example, renaming it to \u201cepsilon-2-zeta.\u201d<\/p>\n<p>We can avoid this by adding the start of string \u201c<code>^<\/code>\u201d and end of string \u201c<code>$<\/code>\u201d\u00a0<em>metacharacters<\/em>\u00a0to the first clause of the expression.<\/p>\n<pre>ls<\/pre>\n<pre>rename 's\/^gamma$\/epsilon-2\/' *<\/pre>\n<pre>ls<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808023\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/14-7.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Limiting a renaming action to entire directory names only\" width=\"644\" height=\"150\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This leaves the directory \u201cepsilon-2\u201d untouched.<\/p>\n<h2 id=\"using-rename-with-other-commands\"><span class=\"ez-toc-section\" id=\"Using_rename_With_Other_Commands\"><\/span>Using rename With Other Commands<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>We can use other commands to locate the directories we want <code>rename<\/code> to work on. If we have a set of nested directories and we want to rename any that end in \u201c-old\u201d so they end in \u201c-archive\u201d, we can achieve that by using <code>find<\/code> and <code>xargs<\/code>.<\/p>\n<p>We need to use <code>xargs<\/code> because <code>rename<\/code> doesn\u2019t accept piped input. The <code>xargs<\/code> command overcomes that problem by accepting the piped input and adding to the command line of another command as a command line parameter.<\/p>\n<p>Our command looks like this:<\/p>\n<pre>find . -depth -type d -name \"*-old\" | xargs -r rename \"s\/old$\/archive\/\"<\/pre>\n<ul>\n<li><strong>.<\/strong>: We tell find to start searching in the current directory. This could be any path, of course.<\/li>\n<li><strong>-depth<\/strong>: Use a depth-first search. This means the contents of deeper nested subdirectories are processed before higher ones.<\/li>\n<li><strong>-type d<\/strong>: Search for directories, not files.<\/li>\n<li><strong>-name \u201c*-old\u201d<\/strong>: The search clue. We\u2019re looking for directories with names ending in \u201c-old.\u201d<\/li>\n<li><strong>|<\/strong>: We\u2019re piping the output from find into the <code>xargs<\/code> command.<\/li>\n<li><strong>xargs -r<\/strong>: The <code>-r<\/code> (no run if empty) means don\u2019t run the command if there are no matching directories.<\/li>\n<li><strong>rename \u201cs\/old$\/archive\/\u201d<\/strong>: The <code>rename<\/code> command to be run.<\/li>\n<\/ul>\n<p>Our directory tree looks like this before the command.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808025\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/15-7.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"The directory tree before our renaming command\" width=\"644\" height=\"270\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>We run our command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808026\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/16-8.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Our renaming command using find, xargs, and rename\" width=\"644\" height=\"95\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>And we can see that all of the matching directories including the nested ones have been renamed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-808027\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/17-4.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"The directory tree after the renaming command\" width=\"644\" height=\"270\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<h2 id=\"wrap-up\"><span class=\"ez-toc-section\" id=\"Horses_for_Courses\"><\/span>Horses for Courses<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Renaming a directory doesn\u2019t need anything more than <code>mv<\/code>. If you prefer GUI applications you can use your file browser. If you\u2019ve got a lot of directories to rename, and especially if they\u2019re scattered throughout a directory tree, you\u2019re going to need the flexibility of <code>rename<\/code>.<\/p>\n<p><strong>RELATED:<\/strong> <strong><em>How to Manage Files from the Linux Terminal: 11 Commands You Need to Know<\/em><\/strong><\/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\/807990\/rename-directory-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;How to Rename a Directory on Linux&#8221; fatmawati achmad zaenuri\/Shutterstock.com Renaming a directory in Linux is easy, and there are plenty of ways to go about it. From renaming a single directory to finding and renaming many, here\u2019s how to do it. Your Data Is Safe Renaming directories is something we all need to do&#8230;<\/p>\n","protected":false},"author":1,"featured_media":462477,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/03\/shutterstock_321627716.png?height=200p&trim=2,2,2,2","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-462476","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\/462476","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=462476"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/462476\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/462477"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=462476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=462476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=462476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}