Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just want to move dirs. I looked successively at mv, cp and rsync, since each tool in turn didn't seem to have the option to remove directories from source after copying them. For instance, mv needs files, not dirs, when src and dst are on different devices:

"inter-device move failed: src to dst; unable to remove target: Is a directory"

Perhaps the simplest way to do this is by using an additional deletion cmd, although I'd prefer not to use it, since that increases risk of data loss.

share|improve this question
up vote 3 down vote accepted

As Bob said. Unfortunately I cannot (yet) comment, so I have to place my adjustments here. I'd suggest using a slightly modified version of Bobs command:

cp -rp source-dir target-dir && rm -r source-dir;

The double-ampersand ensures the second command is only executed if the first finishes successfully -- it would be a horror if the copy fails for some reason (e.g. not enough space on the target volume), and the source would be deleted nevertheless...

share|improve this answer
Good catch! I've never seen that structure before; learn something new every day. – BellevueBob Jul 1 '12 at 23:40
So I give you one more helpful hint connected to this one: while the && means "AND (if successful)", there's also the double-pipe || meaning "OR (if that failed)" -- quite helpful in scripts, e.g. when you need to mount the target first, then copy things over, do something else, etc.; if mount fails, the remaining script makes no sense -- so you could use a construct like mount /path/to/target || { echo "Mount failed, aborting!"; exit 1 } – Izzy Jul 2 '12 at 6:33

Actually, mv can "move" directories; but it cannot move across devices or file systems. It runs very fast because all it does is redefine the file pointer; the contecnts themselves are not copied.

So, you need two commands (copy then remove). On my Solaris system, I move directories with these two commands:

cp -rp source-dir target-dir; rm -r source-dir;

See the man pages to make sure you use the correct syntax for your environment and for the treatment of any symbolic links that might exist.

share|improve this answer
'mv' CAN move across devices and file systems, but it does it as a 'copy' followed by 'delete'. It'll figure out what to do. – lornix Jul 2 '12 at 12:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.