PDA

View Full Version : Linux: Copy directory contents recursively with/out dotfiles to another server



Fli
07-25-2017, 01:23 PM
I found this command and so happy about that that i want to share it.


scp -P 22 -r /home/user/[!.]* destinationserver:/home/user/

it will copy /home/user/ and all the content inside it recursively into remote server (example: 1.2.3.4:/home/user/)
The "[!.]*" part will exclude all dotfiles and dotfolders (ones that starts with dot)
-P is ssh port of the remote server

another way might be rsync:


rsync -avz --ignore-existing --exclude=.[!.]* --human-readable /home/user/ -e "ssh -p 22" root@destinationserver:/home/user/

-a (archive)
-v (verbose)
-z (save bandwidth by compressing)
--ignore-existing (should not overwrite any files of same name that already exist on destination. Else one may use -u switch to update remote files)