Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy a directory structure with file names without content

I have a huge directory structure of movie files. For analysis of that structure I want to copy the entire directory structure, i.e. folders and files however I don't want to copy all the movie files while I want to keep there file names. Ideally I get zero-byte files with the original movie file name.

I tried to and then rsync to my remote machine which didn't fetch the link files.

Any ideas how to do that w/o writing scripts?

like image 329
Juergen Riemer Avatar asked Aug 14 '12 05:08

Juergen Riemer


People also ask

How do I copy a directory structure without files Total Commander?

To copy directory structure without copying any files using Total Commander, enter |*. * into 'Only files of this type' field. This will exclude all files. Save this answer.

How do I copy a folder structure without files in Outlook?

The trick to copy the folder structure of your current mailbox is to archive the mailbox with a date so far in the past that none of your emails are actually being archived. This will create an archive file which contains all of your current folders but will all be empty as well.


1 Answers

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 (*/)

like image 186
Chen Levy Avatar answered Sep 19 '22 00:09

Chen Levy