Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm far away from being an expert, but I also did a little digging (which might be surface for people with more knowledge). "man mv" on Ubuntu 15.04 starts off with "mv - move (rename) files" and the Description starts with "Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY".

This is pretty much the result of the blog post, right? So it's not really a surprise that it only renames in some cases. It's not really a frontend for rename(2), it's only using rename in some cases (which might be common) as optimization. Atomic file system changes are simply a nice side effect.

Or am I understanding the quoted two sentences incorrectly?



There are different things that "move" can mean. rename(2) can "move" in a safe way, but not across devices.

> Atomic file system changes are simply a nice side effect.

Disagree.

Also, my article was to show how mv's task is so complex that it can fail and eat your data even if atomicity is not a requirement.


Okay, haven't got that so far. Maybe I'm missing some skillset to understand.


You've understood the general use description of mv (copy-rename-delete), but what OP demonstrates is a situation in which it does something unexpected (and inappropriate) when dealing with mounted directories.

See the part where he creates file 'bar' in mounted directory /mnt, attempts to move /mnt within itself to /mnt/foo, then asks to show the directories containing /mnt.

The result is that the mv fails (so it shouldn't do anything, right?), but still creates an additional directory (/mnt/foo) that now contains 'bar' and has (destructively) altered the fs hierarchy.

However, when he tries it again after unmounting /mnt, the behavior is completely normal for any other file-- mv fails, nothing happens, /mnt/bar hierarchy is preserved, no /mnt/foo created.


Thanks, now I understand what's going on! Great explanation!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: