copy a directory structure with file names without content

。_饼干妹妹 提交于 2019-12-21 03:39:35

问题


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?


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




回答2:


On ubuntu you can try:

cp -r --attributes-only <source_dir> <target_dir>

It doesn't copy file data. From manpage of cp

--attributes-only
          don't copy the file data, just the attributes

Note: I'm not sure this option available for other distributions, if anybody can confirm please update the answer.




回答3:


ls > listOfMovie.txt; You will have the list of your films in a .txt file .For multiple directories see the man page.



来源:https://stackoverflow.com/questions/11946465/copy-a-directory-structure-with-file-names-without-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!