#!/bin/bash

#!/login
#!/register

Partially move a directory structure


Let’s assume you have the following directory structure:
 
blindcoder@ceres:~/tmp$ tree 
. 
|-- new 
`-- old 
    |-- a 
    | `-- foo 
    | `-- blah a 
    |-- b 
    | `-- foo 
    | `-- blah b 
    |-- c 
    | `-- foo 
    | `-- blah c 
    |-- d 
    | `-- foo 
    | `-- blah d 
    `-- e 
        `-- foo 
            `-- blah e 

and you want to move all the "blah*" files into the directory new while preserving the directory structure.
The command you need is this:
 
blindcoder@ceres:~/tmp$ mv_partial old/ new/ ’blah *’ 

And the directory structure will now look like this:
 
. 
|-- new 
| |-- a 
| | `-- foo 
| | `-- blah a 
| |-- b 
| | `-- foo 
| | `-- blah b 
| |-- c 
| | `-- foo 
| | `-- blah c 
| |-- d 
| | `-- foo 
| | `-- blah d 
| `-- e 
| `-- foo 
| `-- blah e 
`-- old 
    |-- a 
    | `-- foo 
    |-- b 
    | `-- foo 
    |-- c 
    | `-- foo 
    |-- d 
    | `-- foo 
    `-- e 
        `-- foo 

Note that mv_partial will ’’’not’’’ remove empty directories!
Make sure to put the third parameter to mv_partial (the wildcard) into single apostrophes to prevent your shell from interpreting it.

Edit | History | Subscribe