I have a directory tree that looks like this (simplified, in truth there are hundreds of folders):
.
├── a
│ └── b
│ └── a.h5
├── b
│ ├── b
│ │ └── e.h5
│ └── c
│ ├── a.h5
│ └── b.h5
├── c
│ └── b
│ └── a.h5
├── d
│ ├── a.h5
│ └── e.h5
└── e
└── e.h5
Basically, some .h5
files are at depth 1 (ex. d/a.h5
, e/e.h5
) and some files are are depth 2 (ex. b/b/e.h5,
b/c/b.h5
, ...)
I would like to move up only the files at depth 2, so that they all lie at depth one, as in:
.
├── a
│ └── a.h5
├── b
│ ├── e.h5
│ ├── a.h5
│ └── b.h5
├── c
│ └── a.h5
├── d
│ ├── a.h5
│ └── e.h5
└── e
└── e.h5
I know that */*/*.h5
matches the files i'm interested in (tested via ls */*/*.h5
), but I tried mv */*/*.h5 */*.h5
and it made a mess.
Duplicate files would ideally be handled by renaming, but also prompting is okay. How should I procede?
P.S: I've seen:
- https://superuser.com/questions/62141/how-to-move-all-files-from-current-directory-to-upper-directory
- How do you bulk move files up one directory safely?
But they both apply to single directories.
for
loop can deal with any file name, why did you add the extremely fragileawk/ls
one? – terdon Oct 27 '15 at 13:11