1

I want to duplicate a folder and all the subfolders, but I do not want to duplicate the contents of the files in this directory.

Let's say the folder I want to duplicate is

Folder0
     Folder00
          File000.x      1GB
          File001.x      500MB
     Folder01
          File010.x      600MB

I want to create a duplicate that is like

Folder0
     Folder00
          File000.x      1KB
          File001.x      1KB
     Folder01
          File010.x      1KB

How would you advise I go about this?

Alternatively, I can first create a regular duplicate of the folder, and then scrub the contents of each file.

0
1

You can use find:

find src/ -type d -exec mkdir -p dest/{} \; \
       -o -type f -exec touch dest/{} \;

Find directory (-d) under (src/) and create (mkdir -p) them under dest/ or (-o) find files (-f) and touch them under dest/.

This will result in:

dest/src/<file-structre>

You can user mv creatively to resolve this issue.


Other (partial) solution can be achieved with rsync:

rsync -a --filter="-! */" sorce_dir/ target_dir/

The trick here is the --filter=RULE option that excludes (-) everything that is not (!) a directory (*/)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.