SCP a file that match a particular pattern and extension

10,872

Solution 1

This will do your job:

scp -v user@remotehost:/location/KMST_DataFile_*.kms

Solution 2

The main thing here is to use recursive mode -r even if you copy files and not directories. It works.

If you want to copy files that start with "val" and contain also the string "v2" then use:

scp -r [email protected]:/media/Data/results/val*v2* /Users/makis/Desktop/

Here, vecs*v2* will expand and get only files that start with val and also contain v2 string.


Similarly, if the files end with .png for example use:

scp -r [email protected]:/media/Data/results/val*.png /Users/makis/Desktop/
Share:
10,872
Nathanael
Author by

Nathanael

Updated on June 05, 2022

Comments

  • Nathanael
    Nathanael almost 2 years

    I am trying to SCP a file from a remote host onto local host.

    The file on the remote host would be, KMST_DataFile_[MMDDYY]T[HHMM].kms

    I have come up with 2 SCP commands, but I was wondering if there's a way to combine these, to only SCP file that match both the file name pattern above and the extension .kms

    scp -v user@remotehost:/location/KMST_DataFile_*

    scp -v user@remotehost:/location/{*.kms}

  • Erik Bennett
    Erik Bennett almost 9 years
    Also note that his doesn't answer the question in a clever globbing manner, that is one file glob which catches all of the files, but is rather a more generalized solution for when a file glob won't do.
  • Bouncner
    Bouncner over 6 years
    Doesn't really help, or am I wrong? At least from MacOS to Ubuntu, the asterix is not expanded.
  • sale108
    sale108 almost 3 years
    You have to escape the asterisk character, so it'll be more like this: scp -v user@remotehost:/location/KMST_DataFile_*.kms