2

How to ignore certain files when using the scp command? I have the following file structure on the Linux server :

Everything >

  • NeedThis
  • NeedThisToo
  • DontNeedThis

I want to get NeedThis and NeedThisToo and ignore DontNeedThis. I can't just use two separate scps as in reality there are a few hundred files.

Neither can I move nor copy anything (part of this problem, can be seen as a set condition). Does anyone know a solution to my problem?

1
  • 1
    Would you be able to connect to the server with some other program that is easier to use with regards to excluding and including specific names and paths, such as rsync?
    – Kusalananda
    Jun 25 at 10:51

1 Answer 1

4

Using the rsync command in place of scp allows us to be more precise with what we want to exclude. Assuming you want to do a recursive copy of some remote directory to a local directory but want to exclude a name from the operation:

rsync -av --exclude=DontNeedThis user@remote:/some/dir/ /some/dir

The above command would recursively copy the contents of the remote directory /some/dir into the local directory /some/dir, while avoiding anything named DontNeedThis (where DontNeedThis may be some quoted pattern).

Note that the final / on the source path is significant. Without it, you'd copy the directory, not its contents.

For a full explanation of the patterns that you may use to exclude or include things, see the section called "INCLUDE/EXCLUDE PATTERN RULES" in the rsync manual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.