SCP a file that match a particular pattern and extension
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/
Nathanael
Updated on June 05, 2022Comments
-
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 almost 9 yearsAlso 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 over 6 yearsDoesn't really help, or am I wrong? At least from MacOS to Ubuntu, the asterix is not expanded.
-
sale108 almost 3 yearsYou have to escape the asterisk character, so it'll be more like this: scp -v user@remotehost:/location/KMST_DataFile_*.kms