user983223
user983223

Reputation: 1152

Recursively scp except current directory

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.

Upvotes: 9

Views: 13925

Answers (3)

Pierre Templier
Pierre Templier

Reputation: 500

You can use the dot syntax with relative path.

scp -r dir1/. remote:/newfolder

If the remote directory does not exist it is created.

Upvotes: 1

Jonathan Leffler
Jonathan Leffler

Reputation: 755064

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

Upvotes: 20

Vorsprung
Vorsprung

Reputation: 34447

This means copy the list of files made by the shell expansion dir1/* to the remote location remote:/newfolder

scp -r dir1/* remote:/newfolder

Upvotes: 9

Related Questions