Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash command to copy file from one computer to another

Tags:

bash

unix

macos

cp

Wasn't quite sure how to word this but let's say I've used ssh to remote into my friends MacBook (macbook_b) from my MacBook (macbook_a).

What command would I use to copy a file/directory to my MacBook (macbook_a) from my friends MacBook (macbook_b)?

Thank you.

like image 223
MorganR Avatar asked Jun 26 '12 13:06

MorganR


People also ask

How do I copy a file in bash?

You can also copy a specific file to a new directory using the command cp followed by the name of the file you want to copy and the name of the directory to where you want to copy the file (e.g. cp filename directory-name ). For example, you can copy grades. txt from the home directory to documents .

How do I transfer files from one computer to another using command prompt?

Highlight the files you want to copy. Press the keyboard shortcut Command + C . Move to the location you want to move the files and press Command + V to copy the files.

How do I copy a file path in bash?

Holding Shift and right clicking on a file in Windows Explorer gives you an option called Copy as Path . This will copy the full path of the file to clipboard.


2 Answers

You can use scp (Secure Copy).

To copy FROM your machine to friends:

scp file_to_copy [email protected]:/path/to/location

In another direction:

scp [email protected]:/path/locatio/file_name file_name

If you need to copy an entire directory, you'll need to use the recursive flag, like this:

scp -r directory_to_copy [email protected]:/path/to/location
like image 183
maxwell Avatar answered Oct 24 '22 15:10

maxwell


Assuming you're logged in on macbook_b:

scp file_to_copy username@macbook_a:/path/to/destination

or if you're logged in on macbook_a:

scp username@macbook_b:/path/to/file_to_copy local_destination
like image 34
Terje Mikal Avatar answered Oct 24 '22 14:10

Terje Mikal