Otherwise known as: The joy of moving files from Computer A to Computer B.

This is way more exciting than the title lets on. Personally, I often look for an excuse to use these commands.

I had seen scp used a few times at work by the PI, so I decided to try it out for myself when I had 50 image files to transfer over from one terminal to the other. I thought the method was called “File Transferrring” but it has a fancier name of SSH TUNNELING

The definition is quite verbose: “SSH tunneling can be used to secure copy (scp) files to the clusters from your local computer (and vice versa) without having to copy them on to the intermediary bastion host.” Say what?

Really, its a superfluous way of saying “Feel like a computer ninja in miliseconds”

The scp Command Format

Anytime you want to securely copy your files from your remote terminal (ex: your laptop) to your main terminal (ex: your desktop), the command line is designed like so: scp file name loginname@host.com : /Path/To/Folder/In/Main/Terminal

Which ends up looking like this: scp hello.f90 becca@sr2c.cwru.edu:Documents/ Where the : represents your remote home folder, and you can put it in :subfolder/ if you’d like.

After you enter the command telling it to copy your files, it will ask for your password. After pressing ENTER, your files will be transferred over one by one to your chosen terminal. The output looks like this:

becca@sr2c.cwru.edu's password:
hello.f90                                     100%   51     0.1KB/s   00:00

Go ahead, check your desktop. Feel like an evil computer genius. Throw out your flashdrive! Just kidding, please don’t do that

Find your files with grep

My initial task was to convert a bunch of image files manually from .xls to .txt. I tried finding a converstion solution but the spreadsheets were massive and had multiple pages. After hours of manual converstion (meaning: point and click) I was burnt out and wanted to figure out which ones I hadn’t done yet. I could scroll through the list and estimate which particularly named files were “.xls” and which were “.txt”, but there were 50 files to choose from and, you know, I don’t hate myself. So I used grep to address my needs with the command: ls | grep beginning-of-file-name

This command tells the computer to list the files that meet the string search condition. In my case, it was either a file beginning with “PT000” or ending with “.txt”. All the patient files that met this condition of beginning with “PT000” were listed like so:

scp all the files. ALL of them.

After locating the files I wanted and determining I had done them all, I sent the entire bunch of 50 over to my desktop computer. One way to do this is to list multiple files like so: scp file name 1 file name 2 file name 3

In my case, I had a bunch of patient files that I wanted to copy over with complex naming structures, like PT001_AH37890 and PT001_A12890X. No need to type all of that noise by hand! I just used the wildcard asterisk to tell the computer to copy over similarly listed files:scp PT001_A* becca@sr2c.cwru.edu:Documents/Images and boom! all of them are copied over. Or, if you’re copying a folder, then use the Recursive command to move it over: scp -r ~/Documents/Amazon_Turk/ becca@sr2c.cwru.edu:Documents/

I hope this post is useful for others. I’ve actually been using the draft text of this post as a reference for over a month now.