Whenever I try to SCP files (in bash), they end up in a seemingly random(?) order.
I've found a simple but not-very-elegant way of keeping a desired order, described below. Is there a clever way of doing it?
Edit: deleted my early solution from here, cleaned, adapted using other suggestions, and added as an answer below.
2) Unfortunatly, scp will not support wild cards as like rcp.
To copy a directory (and all the files it contains), use scp with the -r option. This tells scp to recursively copy the source directory and its contents. You'll be prompted for your password on the source system ( deathstar.com ). The command won't work unless you enter the correct password.
As Jiri mentioned, you can use scp -r user@host:/some/remote/path /some/local/path to copy files recursively. This assumes that there's a single directory containing all of the files you want to transfer (and nothing else). This the only answer that actually answers the question.
scp -r username@IP:/path/to/server/source/folder/ . . (dot): it means current folder . so copy from server and paste here only.
To send files from a local machine (e.g. your laptop) to a remote (e.g. your calculation server), you can use Merlin2011's clever solution:
scp
command, assuming you have an access key for the remote server:scp -r $(ls -rt) [email protected]:/where/you/want/them/.
Note: if you don't have a public access key it may be better to do something similar using tar
, then send the tar file, i.e. tar -zcvf files.tar.gz $(ls -rt)
, and then send that tar file on its own using scp
.
But to do it the other way around you might not be able to run the scp
command directly from the remote server to send files to, say, your laptop. Instead, you may need to, let's say bring files into your laptop. My brute-force solution is:
cd
into the folder you want to copy files from.ls -rt > ../filenames.txt
pwd
. Now do go up: cd ..
cat filenames.txt | awk '{print "path/to/files/" $0}' > delete_me.txt
tr '\n' ' ' < delete_me.txt > filenames.txt
scp -r [email protected]:"$(cat filenames.txt)" .
Similarly, this assumes you have a private access key, otherwise it's much simpler to tar
the file in the remote, and bring that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With