1

Having the following file hierarchy:

dir
├── dirA
│   └── snapshot
│       └── subdir1
│           └── file1
└── dirB
    └── snapshot
        └── subdir2
            └── file2

I want to move files from each snapshot/subdir directory do the parent directory of snapshot in a single command. That would be:

dir
├── dirA
│   └── file1
│   └── snapshot
│       └── subdir1
└── dirB
    └── file2
    └── snapshot
        └── subdir2

I've tried mv dir/*/snapshot/*/* ../../ but since the destination part ../../ is relative to the working directory it obviously does not work.

Is it possible with bash commands (since I've never written a single line of bash script)?

1

Based on @Don_Christ's keen observation, this answer was edited thereby saving a subshell:

for i in dir/*/snapshot; do
     mv "$i"/*/* "$i"/..
done

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.