I want to copy all files from a remote computer - with some kind of filter. For example, by name: containing the word file somehow like this:

 $ scp user@192.168.1.10:/home/user/$(ls | grep file) 

Does not work. How can I do this - without copying the entire contents of the folder and filtering on the local computer?

  • If there are not many files, you can try this: scp user@remote.host: ~ / \ {file1, file2, file3 \}. - Victor Red
  • Unfortunately, the file names and their number are not known in advance) It is the filter that is needed) - Dofri

1 answer 1

the nested shell (defined by the $() construct) will run on the local machine. therefore, the results of the ls command in this case are unlikely to be useful.

You can copy files containing the word file to the current directory, for example, like this:

 $ scp user@192.168.1.10:/home/user/*file* . 

The search term can be placed in a variable:

 $ v=file scp user@192.168.1.10:/home/user/*$v* . 

Moreover, search quantifiers can be placed in the same variable:

 $ v='*file*' scp user@192.168.1.10:/home/user/$v .