I hope to make scp work with pipe, like
firstlove@chenli ~/Downloads $ ls -liart | tail -n5 | grep 0001
51384329 -rw-r--r-- 1 firstlove firstlove 1440 Oct 31 13:02 0001-add-UNA_PRINT-for-unalign-access-info.patch
51384385 -rw-r--r-- 1 firstlove firstlove 3028 Oct 31 13:02 0001-support-new-em_machine.patch
firstlove@chenli ~/Downloads $ scp `ls -liart | tail -n5 | grep 0001` wuxi-jump-128:/tmp
deepin@172.16.17.221's password:
deepin@192.168.50.128's password:
ls -liart | tail -n5 | grep 0001: No such file or directory
But it promotes "No such file or directory", is there other workaround?
ls -lto generate a list of files to be copied. – AdminBee Oct 31 '19 at 07:51ls -lis a bad idea? and is there any other ways? – Chen Li Oct 31 '19 at 08:19scpwould not know what to do with the long listing output ofls. Can you describe what you want to achieve with your pipeline? It looks as if you want to transfer the files that contain0001out of the five most recently modified files. – Kusalananda Oct 31 '19 at 09:21ls -lis a bad idea is that any command to which you pipe this result would take all output tokens as single input parameters, soscpwould first look for a file called51384328, then trip on-rw-r--r--which it might interpret as a parameter (see e.g. here) etc. Leaving aside you will always be told "never to parse the output of ls", you must at least pipe the output throughawkto select only the last column containing the filenames. – AdminBee Oct 31 '19 at 10:23