Linux – Using scp to get all files in multiple directories

linuxscp

I have a directory structure which looks like A1/B1/C1/files111*, A1/B1/C2/files112*, A1/B2/C1/files121*, A1/B2/C2/files122*, etc. so that all files in all directories are unique. Is there a way to use scp (or some other tool) to pull all terminal files files###* at once?

Best Answer

Since you didn't specify this in the question, I will presume that the directory structure is remote, and you want it local.

What you need to do is use wildcards, but escape them on the client side, so that your local shell ignores them and passes them on. Combine that with a recursive flag (-r), and it should perform how you want it:

scp -r remotemachine:some/directory/files\*   /some/local/target/directory/

The important part is the backslash, as that makes your local shell ignore the asterisk, and pass it on instead. This should allow you to pull all files* from remote, including subdirectories. It will also pull any actual files whos name begin with files*.