9 ms·
> If the destination doesn't exist, `move` renames the source file to the destination name in the current directory. This behavior is documented in Microsoft's
by magicalist 1y ago
> If the destination doesn't exist, `move` renames the source file to the destination name in the current directory. This behavior is documented in Microsoft's official move command documentation[1].
> For example: `move somefile.txt ..\anuraag_xyz_project` would create a file named `anuraag_xyz_project` (no extension) in the current folder, overwriting any existing file with that name.
Can anyone with windows scripting experience confirm this? Notably the linked documentation does not seem to say that anywhere (dangers of having what reads like ChatGPT write your post mortem too...)
Seems like a terrible default and my instinct is that it's unlikely to be true, but maybe it is and there are historical reasons for that behavior?
[1] https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/move https://learn.microsoft.com/en-us/windows-server/administrat...
- gerdesj 1y agoI've actually read that Microsoft documentation page you and the OP linked to and nowhere does it describe that behaviour.
- deleted 1y ago[deleted]
- ianferrel 1y agoThat's basically what linux `mv` does too. It both moves files to new directories and renames files. mkdir some_dir mv file.txt some_dir # Put file.txt into the directory mv other_file.txt new_name.txt # rename other_file.txt to new_name.txt
- do_not_redeem 1y agoLinux's mv does not have this particular failure mode. $ touch a b c $ mv a b c mv: target 'c': Not a directory
- fireattack 1y agoThat's not what OP encountered. The "failure" mode is mv file ../folder where folder is not a folder (non-exist, or is a file). And Linux will happily do this too.
- do_not_redeem 1y ago$ mkdir -p /tmp/x/y/z $ cd /tmp/x/y/z $ touch a b c $ mv a b c ../notexist mv: target '../notexist': No such file or directory
- fireattack 1y agoDo it with one file?
- deleted 1y ago[deleted]
- whilenot-dev 1y ago$ mv a ../notexist $ echo $? 0
- do_not_redeem 1y agoThat's not what OP encountered. > When Gemini executed move * "..\anuraag_xyz project", the wildcard was expanded and each file was individually "moved" (renamed) to anuraag_xyz project within the original directory. > Each subsequent move overwrited the previous one, leaving only the last moved item In a different scenario where there was only one file, the command would have moved only that one file, and no data would have been lost.
- fwip 1y agoDunno about Windows, but that's how the Linux `mv` works.
- deleted 1y ago[deleted]
- crazygringo 1y agoFirst, I think there's a typo. It should be: > 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...
- magicalist 1y agoOK yeah, I feel dumb now, as that's fairly obvious as you write it :D I think the current folder claim just broke my brain, but I believe you're right about what they meant (or what ChatGPT meant when it wrote that part). 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).
- crazygringo 1y agoThe current folder thing broke my brain too. I literally had to go to my terminal to make sure it didn't work that way, and confirm it was a typo. It was only after that I realized what the author meant to say...
- int_19h 1y agoInterestingly, there's no reason for this to be the case on Windows given that it does, in fact, have a separate command (`ren`) which only renames files without moving. Indeed, `ren` has been around since DOS 1.0, while `move` was only added in DOS 6. Unfortunately, for whatever reason, Microsoft decided to make `move` also do renames, effectively subsuming the `ren` command.
- layer8 1y agoThe move command prompts for confirmation by default before overwriting an existing file, but not when invoked from a batch file (unless /-Y is specified). The AI agent may be executing commands by way of a batch file. However, the blog post is incorrect in claiming that move * "..\anuraag_xyz project" would overwrite the same file repeatedly. Instead, move in that case aborts with "Cannot move multiple files to a single file".