简体   繁体   中英

Copy a directory structure and only touch the copied files

I want to mimic copying a directory structure recursively (as in cp -r or rsync -a ), but only touch the copied files, ie make all the copied files empty.

The specific use case is for a Snakemake pipeline; Snakemake looks for existing files in order to decide whether to re-run a pipeline step, and I want to make it believe the steps have already been run while avoiding fully downloading all the files.

This is a little kludgy, but you could pipe the output of find or rsync -nv into a little bash loop with mkdir -p and touch :

find /some/dir -type f | while read FILE; do
  mkdir -p $(dirname $FILE)
  touch $FILE
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM