clobbering a directory with mv
How the heck did I manage it?
I used the command %mv dir1 /path/to/dir2 with the intent of making dir1 a subdirectory of dir2. That is, so it would end up at /path/to/dir2/dir1 But instead, mv renamed dir1 to dir2, clobbering everything in dir2. Yet I've been unable to reproduce this behavior. Trying to figure out what went wrong, I've tried %mv test_dir1 /path/to/test_dir2 numerous times, and it's been working the way I expected and wanted: test_dir1 ends up at /path/to/test_dir2/test_dir1 Can anyone enlighten me? In the meantime, I've aliased mv to 'mv -nv' to try to avoid future mishaps. |
Code:
mv dir1 /path/to/dir2/ |
Directory has to exist before you can copy into it.
Code:
mv /path/dir1/* /path/dir2 Code:
mkdir /path/dir2/dir1 && mv /path/dir1/* /path/dir2/dir1 |
While I'm not sure about why that happened to you, a safer option is usually to use the -t option to explicitly specify the target directory. There's also, of course, the -n option to force no-clobber, or -i for interactive confirmation.
Adding a trailing backslash to the directory name can't hurt either, although I don't know if it has any effect here. Code:
mv -n -t /path/dir2/ dir1 |
All times are GMT -5. The time now is 06:11 PM. |