nico
nico

Reputation: 58

How to copy directory from remote server with scp, excluding a specific subdirectory

I have a directory that I want to copy from a remote server to my desktop. In this directory there is a 40Gb subdirectory that I want to exclude from copying. Until now I used the scp command but there is no -exclude option or anything similar in the man page. By looking online I found a bunch of different ways to copy directory from remote host or exclude a subdirectory when copying locally but no way of how to combine those two. Any help is appreciated. Thanks.

Upvotes: 2

Views: 7724

Answers (2)

Patrick Ferreira
Patrick Ferreira

Reputation: 2063

Another option if you can't use rsync (on a readonly system for exemple) is to tar over ssh.

tar \
  --exclude='temp' \
  --exclude='work' \
  --exclude='logs' \
  -cpf \. # c: create p: preserve owner f: dest file... is output stream
  - \
  apache-tomcat-9.0.17 \. # file or folder to compress/send through ssh
     | ssh [email protected] '(cd ~/my/save/directory; tar xfp - )'

Upvotes: 0

gzh
gzh

Reputation: 3616

To copy with excluding some file or folder, you should try rsync command.

There is --exclude-dir option you can use to exclude subdirectory.

Upvotes: 1

Related Questions