{"record":{"id":"20c0441ec9d5ae27","repo":"uutils/coreutils","slug":"mv-error-inter-device-move-failed-from-to-err","errorCode":null,"errorMessage":"mv-error-inter-device-move-failed (from, to, err)","messagePattern":"mv-error-inter-device-move-failed \\(from, to, err\\)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/uu/mv/src/mv.rs","lineNumber":1413,"sourceCode":"        }\n        // Preserve ownership (uid/gid) from the source\n        let _ = preserve_ownership(from, to);\n    }\n\n    Ok(())\n}\n\nfn rename_file_fallback(\n    from: &Path,\n    to: &Path,\n    #[cfg(unix)] hardlink_tracker: Option<&mut HardlinkTracker>,\n    #[cfg(unix)] hardlink_scanner: Option<&HardlinkGroupScanner>,\n) -> io::Result<()> {\n    // Remove existing target file if it exists\n    if to.is_symlink() {\n        fs::remove_file(to).map_err(|err| {\n            let inter_device_msg = translate!(\"mv-error-inter-device-move-failed\", \"from\" => from.quote(), \"to\" => to.quote(), \"err\" => err);\n            io::Error::new(err.kind(), inter_device_msg)\n        })?;\n    } else if to.exists() {\n        // For non-symlinks, just remove the file without special error handling\n        fs::remove_file(to)?;\n    }\n\n    // Check if this file is part of a hardlink group and if so, create a hardlink instead of copying\n    #[cfg(unix)]\n    {\n        if let (Some(tracker), Some(scanner)) = (hardlink_tracker, hardlink_scanner) {\n            use crate::hardlink::HardlinkOptions;\n            let hardlink_options = HardlinkOptions::default();\n            if let Some(existing_target) =\n                tracker.check_hardlink(from, to, scanner, &hardlink_options)\n            {\n                // Create a hardlink to the first moved file instead of copying\n                fs::hard_link(&existing_target, to)?;\n                fs::remove_file(from)?;","sourceCodeStart":1395,"sourceCodeEnd":1431,"githubUrl":"https://github.com/uutils/coreutils/blob/92995feca29e324a7c559ede91db81c32d9f5d59/src/uu/mv/src/mv.rs#L1395-L1431","documentation":"In `rename_file_fallback` (the cross-device copy+delete path), if the destination exists as a symlink, `mv` removes it first; if that removal fails, the ENOLINK/EXDEV-style failure is re-raised as `mv-error-inter-device-move-failed` with source, target, and the underlying error embedded.","triggerScenarios":"Cross-filesystem `mv file /other/mount/file` where `/other/mount/file` is a symlink and `fs::remove_file(to)` fails (permissions, read-only mount, EBUSY).","commonSituations":"Moving files across mount points / network shares onto stale symlinks, read-only or administratively locked destinations, Windows junction/symlink targets without privileges.","solutions":["Remove the destination symlink manually and retry the mv","Check permissions/write access on the destination directory (`ls -ld $(dirname to)`)","If the destination is on a read-only mount, remount read-write or choose another target","Copy instead of moving (`cp file to && rm file`) to avoid the remove-then-rename fallback"],"exampleFix":"// before\nmv data.csv /mnt/usb/data.csv   # /mnt/usb/data.csv is an unremovable symlink\n// after\nrm /mnt/usb/data.csv && mv data.csv /mnt/usb/data.csv","handlingStrategy":"retry","validationCode":"if [ -L \"$to\" ]; then rm -f \"$to\" || { echo 'cannot remove dest symlink' >&2; exit 1; }; fi","typeGuard":null,"tryCatchPattern":"match mv_result {\n    Err(e) if e.to_string().contains(\"inter-device move failed\") => {\n        eprintln!(\"cross-device move failed; check destination symlink permissions: {e}\");\n    }\n    r => r?,\n}","preventionTips":["Remove stale symlinks at destinations before cross-filesystem moves","Check write permissions on the destination directory","Do not target read-only mounts with mv","Prefer cp + rm for predictable cross-device transfers"],"tags":["mv","filesystem","cross-device","symlink"],"backgroundTag":"cross-device-move-failed","analyzedSha":"92995feca29e324a7c559ede91db81c32d9f5d59","analyzedAt":"2026-09-20T12:39:35.476Z","contentChangedAt":"2026-09-20T12:39:35.476Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}