1
        | folderA1 | fileA11, fileA12, ...
folderA | folderA2 | fileA21, fileA22...
        |  ...     | ... 

I want to make a copy of it represented as:

        | folderA1 | folderA11, folderA12, ...
folderB | folderA2 | folderA21, folderA22, ...
        | ...      |  ...

The original folderA (and it's structure) remains as it is (unchanged).

I'm trying to create a folder in (folder) B for each file in a (folder) A without the folder itself. I also would like to maintain the directory structure of the original folder (A).

Using this question I'm able to achieve the generation of the above but it contains the folder A itself.

find source/. -type d -exec mkdir -p dest/{} \; \
   -o -type f -exec mkdir -p dest/{} \;

Looks like:

         |         | folderA1 | folderA11, folderA12, ...
 folderB | folderA | folderA2 | folderA21, folderA22, ...
         |         | ...
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Pushpa
  • 113

1 Answers1

2

You could cd into folderA and run the command from there:

cd folderA
find . -type d -o -type f -exec bash -c '
  for path; do mkdir -p "/path/to/folderB/${path/file/folder}"; done
' bash {} +

The parameter expansion ${path/file/folder} renames the each fileXY to folderXY.

If every folder contains files, you can remove the -type d -o.

Freddy
  • 25,565