by crazygringo · 1y ago · 0 comments
> would create a file named `anuraag_xyz_project` (no extension) in the PARENT folder, overwriting any existing file with that name.
But that's how Linux works. It's because mv is both for moving and renaming. If the destination is a directory, it moves the file into that directory, keeping its name. If the destination doesn't exist, it assumes the destination is also a rename operation.
And yes, it's atrocious design by today's standards. Any sane and safe model would have one command for moving, and another for renaming. Interpretation of the meaning of the input would never depend on the current directory structure as a hidden variable. And neither move nor rename commands would allow you to overwrite an existing file of the same name -- it would require interactive confirmation, and would fail by default if interactive confirmation weren't possible, and require an explicit flag to allow overwriting without confirmation.
But I guess people don't seem to care? I've never come across an "mv command considered harmful" essay. Maybe it's time for somebody to write one...
Unfortunately, for whatever reason, Microsoft decided to make `move` also do renames, effectively subsuming the `ren` command.
But at least mv has some protection for the next step (which I didn't quote), move with a wildcard. When there are multiple sources, mv always requires an existing directory destination, presumably to prevent this very scenario (collapsing them all to a single file, making all but the last unrecoverable).
D:\3\test\a>move 1 ..\1
Overwrite D:\3\test\1? (Yes/No/All):
If anything, it's better than Linux where it will do this silently.e.g. "mv --backup -- ./* wrong-location-that-doesnt-exist" will rename your files in an unhelpful fashion, but won't lose any.
e.g. "mv --no-clobber -- ./* wrong-location-that-doesnt-exist" won't overwrite files.
It's trivial to setup an alias so that your "mv" command will by default not overwrite files. (Personally I'd rather just be wary of those kinds of commands as I might be using a system where I haven't customised aliases)