-1

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
5

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
  • for dir in */ also works for restricting loop to directories only. – cas May 26 '16 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.