<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Shell (Linux/MacOS) - Rename file to the directory name it is in, and move it out of the directory - Home Theatre				            </title>
            <link>https://www.tweaking4all.com/forum/home-theatre/shell-linux-macos-rename-file-to-the-directory-name-it-is-in-and-move-it-out-of-the-directory/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Tue, 21 Jul 2026 02:13:05 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>Shell (Linux/MacOS) - Rename file to the directory name it is in, and move it out of the directory</title>
                        <link>https://www.tweaking4all.com/forum/home-theatre/shell-linux-macos-rename-file-to-the-directory-name-it-is-in-and-move-it-out-of-the-directory/#post-4150</link>
                        <pubDate>Wed, 27 Apr 2022 15:15:42 +0000</pubDate>
                        <description><![CDATA[Little script that may be helpful to others.
I have several directories, each holding own or more files (with different file extensions!), something like this:
- Somedirectory
    - File1...]]></description>
                        <content:encoded><![CDATA[<p>Little script that may be helpful to others.</p>
<p>I have several directories, each holding own or more files (with different file extensions!), something like this:</p>
<pre contenteditable="false">- Somedirectory
    - File1.txt
    - File2.doc
- AnotherDir
    - Banana.png
    - 1234.xls
- Somerandomname
    - Test1.txt
    - Test2.doc</pre>
<p> </p>
<p>And I watned this as a result:</p>
<pre contenteditable="false">- Somerandomname    (empty dir)
- Somedirectory.txt
- Somedirectory.doc
- AnotherDir     (empty dir)
- AnotherDir.png
- AnotherDir.xls
- Somerandomname     (empty dir)
- Somerandomname.txt
- Somerandomname.doc</pre>
<p> </p>
<p> After some playing with Terminal/Shell (this will probably not work under Windows), this script will do that for all directories in the current directory:</p>
<pre contenteditable="false">for f in */* ;do fp=$(dirname "$f"); ext="${f##*.}" ; mv "$f" "$fp"."$ext" ;done</pre>
<p> </p>
<p>Hope this is useful to someone ...</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/home-theatre/">Home Theatre</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/home-theatre/shell-linux-macos-rename-file-to-the-directory-name-it-is-in-and-move-it-out-of-the-directory/#post-4150</guid>
                    </item>
							        </channel>
        </rss>
		