0

This is kind of tricky

I have a folder, and inside this folder are several subfolders, each subfolder contains one subfolder of it's own (subsubfolder), I want to move these 'subsubfolders' to the original folder.

This is what it looks like right now:

Archives/
│
├── Records_A/
│   └── Folder_1/
|       └── Item_1.png
│
├── Records_B/
│   └── Folder_2/
|       └── Item_2.png
│
├── Records_C/
│   └── Folder_3/
|       └── Item_3.png
│
├── Records_D/
│   └── Folder_4/
|       └── Item_4.png
│
├── Records_E/
│   └── Folder_5/
|       └── Item_5.png

...

I want to move all the subsubfolders so that it looks like this:

Archives/
│
├── Folder_1/
│   └── Item_1.png
│
├── Folder_2/
│   └── Item_2.png
│
├── Folder_3/
│   └── Item_3.png
│
├── Folder_4/
│   └── Item_4.png
│
├── Folder_5/
│   └── Item_5.png
│
├── Records_A/
│
├── Records_B/
│
├── Records_C/
│
├── Records_D/
│
├── Records_E/

...

Is there anyway to do this in bash?

I am not looking to move any files here, only folders

Note that the names of the subfolders don't always start with 'Record_' And The names of the subsubfolders don't always start with'Folder_', I'm looking for a general solution based on the directory structure rather than the names.

EDIT: I found a solution if anyone else has the same problem:

mv -v ./Records_*/* ./

just replace the "Records_" with whatever prefix the folders' names begin with (or just leave * for everything).

1 Answers1

0
$ tree
.
├── Records_A
│   └── Folder_1
│       └── Item_1.png
├── Records_B
│   └── Folder_2
│       └── Item_2.png
├── Records_C
│   └── Folder_3
│       └── Item_3.png
├── Records_D
│   └── Folder_4
│       └── Item_4.png
└── Records_E
    └── Folder_5
        └── Item_5.png

10 directories, 5 files
[/tmp/Archives]$ find . -mindepth 2 -maxdepth 2 -type d | xargs -I {} mv {} .
[/tmp/Archives]$ tree
.
├── Folder_1
│   └── Item_1.png
├── Folder_2
│   └── Item_2.png
├── Folder_3
│   └── Item_3.png
├── Folder_4
│   └── Item_4.png
├── Folder_5
│   └── Item_5.png
├── Records_A
├── Records_B
├── Records_C
├── Records_D
└── Records_E

10 directories, 5 files
Nykakin
  • 3,744