linux overwrite directory

How do you overwrite a directory with another directory? I know you can delete your directory then copy your directory over, but I would think there would be a way to do this in one step.

Here is a way to do it in one step:

mount --bind olddir newdir

Note that the old content isn't lost, just hidden by the overlay mount.

I think, that You're looking for:

mv -T /path/to/dir1 /path/to/dir2

with -T target directory is treated as file - so it will be overwritten.

mv -T 

will only work if dir2 is not empty.

Actually it will work only if dir2 IS empty :slight_smile:
But when there are some files in it, it simply won't work...
So for now, I don't have any solution better than:

rm -rf /path/to/dir2 && mv /path/to/dir1 /path/to/dir2

I think, that filesystem won't allow to do such thing with simple 'mv'.
:slight_smile:

True.
When source and destination are both directory names, the destination for "mv" is relative to the target directory. If the target directory does not exist "mv" will create it, otherwise "mv" will create the new directory under the target directory.