2

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)?

2

1 Answer 1

2

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
0

You must log in to answer this question.

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