In a GUI environment, a drag-and-drop with replace will replace files and entire directories (including contents) with whatever is being copied in. Is there a way to accomplish this same intuitive result with the 'mv' command?
The core function of
mv (despite its name) is to rename an object. One of the guarantees that UNIX makes is that renames are atomic -- you're never allowed to see a partially completed rename. This guarantee can be very useful if you want to change a file (
/etc/passwd, for example) that other programs may be looking at, and you want them to see either the old or new version of the file, and no other possibility. But a "recursive rename" like you describe would break that guarantee -- you could stop it in the middle and you'd have a half-moved tree and probably a mess -- and so it doesn't really fit in with the philosophy of
mv. That's my guess as to why
mv -r doesn't exist.
(Never mind that
mv breaks that philosophy in other, smaller ways. For example,
mv actually does a
cp followed by
rm when moving files from one filesystem to another.)
Enough philosophy. If you want to recursively move ("drag-drop") a tree from one place to another on the same filesystem, you can get the efficiency and speed of
mv as follows (for example):
cp -al source/* dest/ && rm -r source/*
-l flag to
cp means "create a hard link instead of copying" -- it's effectively creating a new filename that points to the same file data as the old filename. This only works on filesystems that support hard links, though -- so any native UNIX-ish filesystem is fine, but it won't work with FAT.
&& means "only run the following command if the preceding command succeeded". If you like, you can run the two commands one at a time instead.
I don't think you can replicate the drag-drop behavior you're describing with
mv, as non-empty subdirectories in the target won't be replaced.
rsync? Something like
rsync -a -r source/ target/? Run with the
-v -n to do a verbose dry-run first to make sure it does what you want.
mv -f /path/to/source/folder/* /destination/folder/
Will move everything in /path/to/source/folder, including files and directories to /destination/folder.
And will overwrite existing files and directories.
You're probably going to want to change the correct answer to this:
say I have:
test/ test/index.php test/images/ test/images/a.jpg test/images/thing.png
and I want to move these things to /site
so it looks like:
site/ site/public/ site/public/index.php site/public/a.jpg site/public/thing.png
I can go:
cd images && pick a.jpg thing.png cd .. && pick index.php && cd .. && mkdir site && mkdir site/public && cd site/public && drop
This is literally cut & paste.