Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to repeat

touch ../template/filename

where filename comes from find. I want xargs to apply the touch operation, but I dont want it to insert a space like it usually does which derives into:

touch ../template/ filename

Here is my incomplete command. How Do I complete it?

find *.html | xargs touch ../template/WHAT-NOW
share|improve this question
find -name "*.html" | xargs -d"\n" -I"{}" touch ../template/{}

find -name "*.html" -exec touch ../template/{} \;

Note that find *.html is wrong, since wildcards are expanded before command execution.

share|improve this answer
The find command gives me ./photos_each.html when I actually meant photos_each.html. I want simply the filename – aitchnyu Sep 8 '12 at 13:51
@aitchnyu: They are equivalent here. Both ../template/photos_each.html and ../template/./photos_each.html should work. – grawity Sep 8 '12 at 14:41

This is easier to write as a shell loop. For instance, in C shell you might write:

foreach i (`find -name "*.html"`)
   touch ../template/$i

And here it is in bash:

for i in `find -name "*.html"`
   touch ../template/$i

And in my Hamilton C shell (full disclosure: I'm the author), I added a "..." wildcard to tree-walk, so you could write:

foreach i (.../*.html)
   touch ../template/$i
share|improve this answer

Consider using GNU Parallel instead. That way you avoid nasty surprises if the filenames contain space ' or ":

find *.html | parallel -X touch ../template/{/}

See the intro videos to learn more:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.