5

Osx mv and cp does not have the --parents option, so how does one emulate it ?

I.e. mv x/y/a.txt s/x/y/a.txt when s is empty gives a no directory found error unless one does a mkdir first which is rather cumbersome when trying to do this did thousands of files.

Max Rydahl Andersen
  • 3,630
  • 2
  • 23
  • 28

1 Answers1

5

The solution (which works on all platforms that has an rsync) is:

Use find or some other tool to create a file with the files you want moved/copied, i.e.

find *.mp3 > files.txt

Then use rsync files-from to specify it and by using --remove-source-files it behaves like a mv -p and without it works like cp -p:

rsync --files-from=files.txt --remove-source-files src dest 

Slower than a native mv/cp but its resumable and rsync got alot more options that can otherwise help too for cleaning up your files.

Max Rydahl Andersen
  • 3,630
  • 2
  • 23
  • 28
  • Good call. Additionally, you could install the MacPorts version of the command-line utilities, but this could very likely break a lot of stuff if you were to replace the default utils entirely either via PATH, EXPORT, ALIAS, or symlinks. – Cloud Sep 12 '12 at 23:43
  • Good solution, but may require the additional step of moving the output (copied) files. For example, I am trying to move all wav audio files from `/Volumes/Music.../iTunes/...` (an external disk) to `~/Music/iTunes/...` (internal disk)... I ended up with the extra sub tree of `/Volumes/Music.../iTunes/...` *inside* the output directory, but this is easy to solve by moving the files about. – FreelanceConsultant Aug 19 '16 at 16:38