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?

  • why not just use the full path in your find command?
    – h3rrmiller
    Jan 17, 2013 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, 2013 at 5:53
  • oh, i understand now. use rsync instead of find ... -exec. rsync synchronizes file systems/directories
    – h3rrmiller
    Jan 17, 2013 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, 2013 at 6:48
  • you can specify with wildcards, etc. the man page should have everything you need
    – h3rrmiller
    Jan 17, 2013 at 6:51

1 Answer 1


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

find . -exec mv {} /mountedSystem/{} \;
  • Please be careful when batting around phrases like "does nothing"... cd // ; pwd ; readlink -f .
    – Chris Down
    Jan 17, 2013 at 8:50
  • @ChrisDown Please read the answer carefully before commenting on it ;-) cd /./ ; pwd ; readlink -f . Jan 17, 2013 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, 2013 at 9:05
  • @ChrisDown: I meant a path containing /./. Better now?
    – choroba
    Jan 17, 2013 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, 2013 at 22:41

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