Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

Possible Duplicate:
Manipulate file name piped from find command

How can I alter the path of a file found with find before I run an exec on it? I want to find files and then mv them to a mounted file system that has the same file structure as the system being searched.

Say I found ./home/usr1/dir1/file, I want to move it to /mountedSystem/home/usr1/dir1/file, so all I need is to remove the leading . and append /mountedSystem to the start of the file path before executing the mv. Is there any way to do this safely?

share|improve this question

marked as duplicate by Gilles, jasonwryan, Renan, Chris Down, warl0ck Jan 20 '13 at 0:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

why not just use the full path in your find command? – h3rrmiller Jan 17 '13 at 4:59
I want to move what I found to the equivalent position on the mounted file system. So I need to change the destination path which will be the same other than the first directory. – Aaron Jan 17 '13 at 5:53
oh, i understand now. use rsync instead of find ... -exec. rsync synchronizes file systems/directories – h3rrmiller Jan 17 '13 at 6:18
That looks good, can I specify only files that match a particular pattern/type like find or does it sync the whole system? – Aaron Jan 17 '13 at 6:48
you can specify with wildcards, etc. the man page should have everything you need – h3rrmiller Jan 17 '13 at 6:51

/./ in a middle of a path does nothing. You do not have to remove the dot:

find . -exec mv {} /mountedSystem/{} \;
share|improve this answer
Please be careful when batting around phrases like "does nothing"... cd // ; pwd ; readlink -f . – Chris Down Jan 17 '13 at 8:50
@ChrisDown Please read the answer carefully before commenting on it ;-) cd /./ ; pwd ; readlink -f . – daniel kullmann Jan 17 '13 at 8:59
@danielkullmann So? . does not always "do nothing", it does not always return the current pwd. Such a categorical statement is misleading. – Chris Down Jan 17 '13 at 9:05
@ChrisDown: I meant a path containing /./. Better now? – choroba Jan 17 '13 at 9:43
Thanks this works for my specified problem, but in terms of the question, is there a way to alter the path, for example, if I wasn't able to use the leading part of it and it had to change? – Aaron Jan 17 '13 at 22:41

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