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? Dec 15, 2014 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, 2014 at 20:31
  • I want recreate all jpgs inside emptys/ folder with the extension .tmp. Like photo01.jpg.tmp
    – Claytinho
    Dec 16, 2014 at 12:14

2 Answers 2


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. Dec 15, 2014 at 21:39
  • Thanks Ketan. I improve your suggestion with -exec cp -u --attr...
    – Claytinho
    Dec 16, 2014 at 12:36

Without recreating the subdirectories:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .