Tuesday, April 23, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 9214  / 2 Years ago, tue, january 18, 2022, 7:35:49

I was connected my OpenSSH, but What's the command for ssh to find all files which are *.png and get them at the same time, recursively


More From » command-line

 Answers
3

You can list files of your interest with ssh, then download them with scp:



ssh user@host find /remote_path -iname '*.png' | 
while read pngfile; do
scp user@host:"$pngfile" /local_path
done


All *.png files under /remote_path will be downloaded to /local_path, but the remote directory structure will not be created (all files will be put in the same directory), so you may have problems if you have two files with the same name in different directories.



Edit



The remote find command line should be corrected in this way:



find /remote_path -iname "'*.png'"


where the internal pair of single quotes are needed to avoid local shell pathname expansion of *, wheras the external pair of double quotes are needed to avoid remote shell pathname expansion of *.



The two types of quotes could be exchanges, and other syntaxes could be used, like ''*.png'', ""*.png"" or ""*.png"".



If you don't have .png in remote home directory, there is no difference between the two commands, but it is better to be safe.


[#43946] Thursday, January 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
afyess

Total Points: 437
Total Questions: 120
Total Answers: 107

Location: San Marino
Member since Fri, Jul 3, 2020
4 Years ago
afyess questions
;