Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively scp except current directory

Tags:

unix

scp

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.

like image 927
user983223 Avatar asked Jul 21 '12 18:07

user983223


People also ask

How do I recursively SCP a folder?

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.

Is SCP recursive?

The scp utility is used to transfer files and directories to remote servers, and supports recursive operations.

What is the difference between rsync and SCP?

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.

How do I copy all directories except one in Linux?

Method 1- using rsync command One of the useful option is --exclude. Using exclude option, we can exclude certain files/directories from copying.


1 Answers

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).

like image 80
Jonathan Leffler Avatar answered Nov 10 '22 13:11

Jonathan Leffler