Is there a way to scp
all files in a directory recursively to a remote machine and keep their original filenames but don't copy the directory it is in?
dir1/file
dir1/dir2/file2
so the contents of dir1
would be copied only. dir1
would not be created. The dir2
directory would be created with file2
inside though.
I have tried scp -r dir1 remote:/newfolder
but it creates dir1
in the /newfolder
directory on remote
. I don't want it to create that dir1
directory. Just put all the files inside of dir1
into newfolder
.
To copy a directory (and all the files it contains), use scp with the -r option. This tells scp to recursively copy the source directory and its contents. You'll be prompted for your password on the source system ( deathstar.com ). The command won't work unless you enter the correct password.
The scp utility is used to transfer files and directories to remote servers, and supports recursive operations.
Copying files and directories with SCP or Rsync Secure Copy (SCP) uses SSH to copy only the files or directories that you select. On first use, Rsync copies all files and directories and then it copies only the files and directories that you have changed. It does not copy all the files and directories again.
Method 1- using rsync command One of the useful option is --exclude. Using exclude option, we can exclude certain files/directories from copying.
cd dir1
scp -r . remote:/newfolder
This avoids giving scp
a chance to do anything with the name dir1
on the remote machine. You might also prefer:
(cd dir1; scp -r . remote:/newfolder)
This leaves your shell in its original directory, while working the same (because it launches a sub-shell that does the cd
and scp
operations).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With