Bash Find – How to Create Empty Files with Same Name in Another Location

bashfindtouch

I want create empty files with the same name, but in another location.

Is it possible?

  1. find some files
  2. use only filenames
  3. touch an empty file in another place

Something like this:

find . -type f -name '*.jpg' -exec basename {}.tmp | touch ../emptys/{} \;

Best Answer

you can use the --attributes-only switch of cp for this purpose, eg.

find . -iname "*.txt" -exec cp --attributes-only -t dummy/ {} +

From the man page of cp:

--attributes-only

don't copy the file data, just the attributes

This will create empty files with all attributes of the original file preserved but no contents.

Related Question