Score:0

moving multiple files in multiple directories

gp flag

I have a directory, within are many directories (abc1 abc2 abc3 etc.) that contain a sub-directory - always the same name (MATCHING_STRING) - full of files. I want to remove that sub-directory (MATCHING_STRING), keeping files in their own abc# directory. I don't want all files ending up in 1 location as would happen with mv */* .

before:

Main/
├─ abc1/
│ ├─ MATCHING_STRING/
│ │ ├─ xyz1 │ │ ├─ xyz2
├─ abc2/
│ ├─ MATCHING_STRING/
│ │ ├─ xyz1 │ │ ├─ xyz2

After:

Main/
├─ abc1/
│ ├─ xyz2 │ ├─ xyz1
├─ abc2/
│ ├─ xyz2 │ ├─ xyz1

rfm avatar
mk flag
rfm
Where do want the files to be after the directory is gone? Might help if you gave a before/after example (just a few files) of what you want.
Score:0
jp flag

I would use PowerShell for that (but you can also use the find command)

find Option

You will lose files that have duplicate names

The Folder before

~/test$ tree
.
├── abc1
│   └── string
│       ├── file1
│       └── file2
└── abc2
    └── string
        ├── file1
        └── file2

4 directories, 4 files

Execution

~/test$ for i in */string; do cd $(dirname $i); find . -type f -exec mv '{}' . \;;cd ..; done

The Folder after

~/test$ tree
.
├── abc1
│   ├── file1
│   ├── file2
│   └── string
└── abc2
    ├── file1
    ├── file2
    └── string

4 directories, 4 files

source for the find command source for the loop

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.