I have two folders, and I would like to do:
cp -R folder1/ folder2/
So that I all the sub folders missing in folder2 will be created, and there files copied. And all the folders in folder2 that are missing from folder1 stay the same.
I have two folders, and I would like to do:
cp -R folder1/ folder2/
So that I all the sub folders missing in folder2 will be created, and there files copied. And all the folders in folder2 that are missing from folder1 stay the same.
cp -fR folder1/ folder2/
the -f flag forces the dest file to be deleted if cannot be opened
Also, another option would be to use rsync, see this answer for example:
cp -R folder1/. folder2/
You can use folder1/*
instead, if you don't mind that *
will not match "hidden" files which begin with a .
like .bash_profile
.
If there are files in folder2 with the same name as files in folder1, they will be overwritten without prompting or warning.
Don't use cp
, instead use mv
, Because:
cp
copy all files and it spreads time and I/O, But mv
only change inode:
So:
mv -f dir1/ dir2
rsync
does if you pass --delete). – sourcejedi Feb 23 '17 at 17:22