The Right Answer to the Wrong Question
If you want a quick, atomic move, then mv is the thing to do since man 2 rename
says:
If newpath already exists it will be atomically replaced (subject to a few conditions; see ERRORS below), so that there is no point at which another process attempting to access newpath will find it missing.
Perhaps more importantly, mv is largely a directory entry operation, so it's very quick compared to a file copy in any normal circumstance.
The Right Answer to the Right Question
If you're worried about power outages or unexpected system shutdowns, then:
- Attach an uninterruptible power supply. Really. Solve for the threat model.
- Make sure you're using a battery-backed RAID controller.
- Make critical writes synchronous.
- Use a journaling filesystem that journals data, and not just metadata.
The mv command should be faster, but robustness in the face of catastrophic failures is a hardware or filesystem issue.
file.dat
", do you mean the file is truncated to zero, then filled up again? – Sinegold