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
0

1 Answer 1

7

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .