Move all sub-directory content up one level

My top level directory contains a bunch of sub-directories:

  • af
  • ar
  • ca
  • cs
  • da
  • de
  • el
  • en
  • ... (lots more)

Each of these directories has the exact, same structure. They contain two directories:

  • v2.3.0
  • v3.0.0

I need to move all files from */v2.3.0/*.php up a directory, so we go from:

  • af
    • v2.3.0
      • file1.php
      • file2.php
    • v3.0.0

To this:

  • af
    • file1.php
    • file2.php

Answer

The simplest solution is:

for dir in *; do mv "$dir"/v2.3.0/* "$dir"/; done

To only move php files use:

for dir in *; do mv "$dir"/v2.3.0/*php "$dir"/; done

And to avoid error messages if you have files (an not only directories) in the top level:

for dir in *; do [ -d "$dir" ] && mv "$dir"/v2.3.0/* "$dir"/; done

Leave a Reply

Your email address will not be published. Required fields are marked *