26

i'm trying to move folders to another folders using command line, with overwrite if already exists, but i got error "Is a directory" when using mv..

example:

mv src/test/ dest/

there are many files and folders on src/test/, there are also some files and some folders on dest/

and i want files and folders on dest/ replaced with files and folder from src/test/ if exists, example:

src/test/bla/boo replaces dest/bla/boo
src/test/bla/bla/boo replaces dest/bla/bla/boo

also, everytime one file transfer completed, that one file deleted from src/test/

and overall transfer progress bar would be fine..

what rsync flag should i use to make this happend?

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Kokizzu
  • 24,974
  • 37
  • 137
  • 233

1 Answers1

48

The following command line should achieve what you want:

$ rsync -a --progress --remove-source-files src/test/ dest
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • but it doesn't do "everytime one file transfer completed, that one file deleted from src/test/" – Kokizzu Oct 04 '12 at 20:24
  • 3
    Really? `--remove-source-files` should do exactly that. – Frédéric Hamidi Oct 04 '12 at 21:14
  • nope XD sorry, it does.. my mistake.. thanks ^^ – Kokizzu Oct 05 '12 at 08:06
  • 8
    Well that's not exactly what `mv` does. `mv` a file to another directory in the same partition requires no copy at all, while this `rsync` equivalent will takes a lot time copying the file then delete the source file. – yegle Jan 12 '14 at 20:28
  • 2
    @yegle is right. If you really want to move files within a physical(?) drive, `mv` should be a LOT faster. If you want to move to a different drive such as external HDD, USB stick etc. then the command above is to be preferred to `mv` I think. – Wauzl Apr 21 '15 at 09:07