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/{} \;
  • Do you want the subdirs recreated below emptys/ or just files? – Hauke Laging Dec 15 '14 at 20:22
  • Stick an xargs before the touch and you're close. Though I don't understand what the .tmp is supposed to be. Is it an extension for removal, or are you appending to the filename? – muru Dec 15 '14 at 20:31
  • I want recreate all jpgs inside emptys/ folder with the extension .tmp. Like photo01.jpg.tmp – Claytinho Dec 16 '14 at 12:14

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:


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.

  • 1
    Note that's GNU only. It doesn't preserve attributes unless you tell it which ones to preserve with -p or -a. You might as well use -exec cp --attributes-only -t dummy/ {} + here to avoid running one cp per file. – Stéphane Chazelas Dec 15 '14 at 21:39
  • Thanks Ketan. I improve your suggestion with -exec cp -u --attr... – Claytinho Dec 16 '14 at 12:36

Without recreating the subdirectories:

find . -type f -name '*.jpg' -printf /path/to/emptys/%f\\0 | xargs -0 touch

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.