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.

Forgive me, I am probably not using the right terms to describe the problem and misunderstanding the most basic usage for a couple of common commands.

I have a simple find statement that is locating files that I want to copy. I want to tack on the -exec cp {} and have cp copy the file from the source directory to a new base directory, but include the full path. For example:

"find . -name *.txt" locates /user/username/projects/source.txt "cp {} [now what?]" copies the file to /user/newuser/projects/source.txt

share|improve this question

2 Answers 2

rsync -rlpv --files-from=<(find ...) /user/username/projects /user/newuser
share|improve this answer

If you can be sure that all of the subdirectories exist, then this is a fun option:

cd /user/username/
find . -name \*.gz | sed 's/\.\(.*\)/.\1 ..\/newuser\1/' | xargs -n2 cp
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.