Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

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
1  
@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
end

And here it is in bash:

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

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
end
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: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

share|improve this answer

Your Answer

 
discard

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.