Given /mnt/source/ and /mnt/target/ which are two different places / filesystems.

  • mv /mnt/source/dir /mnt/target/
  • It runs out of space part-way (and stops)

  1. Imagining that /mnt/source/dir is full of directories, sub-directories and files, when the mv fails, are any files removed from /mnt/source/dir ?

  2. Can I safely delete my failure ( rm /mnt/target/dir ), prepare more space on the /mnt/target/ file system, and try the move operation again?

  3. Or perhaps: If I am unable to prepare more space on the /mnt/target/ file system, should I do some sort of "undo" like mv /mnt/target/dir/* /mnt/source/dir/ (with a file manager, to overwrite target files) so I can change my mind and not attempt the move at all?

related: What happens when you force quit a `mv` directory operation between two disks?


Are files removed from /mnt/source/foo ?

Not until the command reports a succes on moving.

$ $ mv --version
mv (GNU coreutils) 8.25


$ info mv

has information on what happens:

mvcan move any type of file from one file system to another. Prior to version 4.0 of the fileutils, mv could move only regular files between file systems. For example, now mv can move an entire directory hierarchy including special device files from one partition to another. It first uses some of the same code that's used by cp -a to copy the requested directories and files, then (assuming the copy succeeded) it removes the originals. If the copy fails, then the part that was copied to the destination partition is removed. If you were to copy three directories from one partition to another and the copy of the first directory succeeded, but the second didn't, the first would be left on the destination partition and the second and third would be left on the original partition.

Mind the 2nd part in bold: it is done on each mv you do so

mv a b c /dir/

will remove "a" in between "a" and "b".

  • So that means YES some files can be removed from /mnt/source/foo and NO I cannot safely delete /mnt/dest/bar? – spiralofhope Jul 15 at 10:26
  • No. It depends on the "mv". "mv /mnt/source/foo /mnt/dest/bar/" if "foo" is 1 file or a directory the deleting will take place after foo is moved. ONLY if you move more files and/or directories in 1 go you need to watch out (so "mv a b c /bar/") – Rinzwind Jul 15 at 10:42
  • I think I'm understanding better. I clarified my question: It is not 1 file, it is many directories, sub-directories and files within the source. The second part of info mv seems to say I must not delete my /mnt/target/. --- It also seems like file managers (in my case spacefm and midnight commander) do not necessarily operate the same way. Maybe they are copying first, and only remove any source files if the operation succeeds? – spiralofhope Jul 16 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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