Search code examples
linuxscp

How to scp files with certain name to another server?


I have some files in a directory called info where I need to copy over files containing keyword food to another server. So the files can be food#give.json, food#take.json etc.

scp -i "t2microkey.pem" -r ~/info/['food' pattern files] ec2-user@example.sky.com:/home/ec2-user/some_dir/

I found out this question in stackoverflow. https://unix.stackexchange.com/questions/138007/copying-files-with-particular-names-to-another-folder but I am not sure how do I use this solution in my case.

Any help will be appreciated.


Solution

  • You can use below command to transfer the file, I just used it and it is working fine for me.

    scp -i ~/<path-to-key>/<key-pair-name>.pem -r ~/info/food#* ec2-user@3.80.81.43:~
    food#give.json                        100%    0     0.0KB/s   00:00    
    food#take.json                        100%    0     0.0KB/s   00:00
    

    Directory Structure :

    <some-directory-name>
            |-- food#give.json
            |-- food#take.json