Search code examples
bashscp

scp on specific files using regex (*)


Hello I have a disrectory in a server such as :

/dir1/dir2/dir3/dir4/
file2_JU.out
file4.out
file2_JU.out
file1_JU.out
file4_JU.out
file4.out

and I would like to scp only the file containing a _JU so I tried ;

scp serve1@:/dir1/dir2/dir3/dir4/file*_JU.out
 /mycomputeur/dir/ 

but it does not work


Solution

  • As I remember scp should send /dir1/dir2/dir3/dir4/file*_JU.out to the remote machine and you need backslashes to prevent the shell from interpreting it.

    scp serve1@:/dir1/dir2/dir3/dir4/file\*_JU.out /mycomput
    

    You can also try:

    scp "serve1@:/dir1/dir2/dir3/dir4/[*_JU.out]" /mycomput
    

    Also:

    scp 'serve1@:/dir1/dir2/dir3/dir4/file*_JU.out' /mycomput
    

    didn't test it