218

I'm trying to copy my .profile, .rvm and .ssh folders/files to a new computer and keep getting a "not a regular file" response. I know how to use the cp and ssh commands but I'm not sure how to use them in order to transfer files from one computer to another.

Any help would be great, thanks!

yosefbennywidyo
  • 163
  • 4
  • 8
alvincrespo
  • 9,224
  • 13
  • 46
  • 60

3 Answers3

477

You can do this with the scp command, which uses the ssh protocol to copy files across machines. It extends the syntax of cp to allow references to other systems:

scp username1@hostname1:/path/to/file username2@hostname2:/path/to/other/file

Copy something from this machine to some other machine:

scp /path/to/local/file username@hostname:/path/to/remote/file

Copy something from another machine to this machine:

scp username@hostname:/path/to/remote/file /path/to/local/file

Copy with a port number specified:

scp -P 1234 username@hostname:/path/to/remote/file /path/to/local/file
Mohamad
  • 34,731
  • 32
  • 140
  • 219
Ether
  • 53,118
  • 13
  • 86
  • 159
  • 1
    I think that OP's use of the phrase 'how to use them in order to transfer' might be rewritten as 'how to use them to transfer'. Wordy perhaps, but not terrifically wrong. – High Performance Mark Sep 14 '10 at 16:44
  • 2
    @High: ah indeed. :) *gets more coffee* – Ether Sep 14 '10 at 16:46
  • 2
    Thanks @Ether, but unfortunately, I keep getting a "not a regular file" response for directories that start with '.' like the .rvm folder im trying to transfer, any tips? – alvincrespo Sep 14 '10 at 16:57
  • 1
    don't worry about it. I got it! I need to use -r (r for recursive) in order to bring in whole directory structures. Thanks so much! – alvincrespo Sep 14 '10 at 17:01
  • 2
    Yes, you can use `-r` for recursive, or just zip up the files and target the zip. – Eric Holmes Jan 16 '14 at 02:19
  • Last command with port must be: scp -P 1234 /path/to/local/file username@hostname:/path/to/remote/file – Tropin Alexey Jun 28 '22 at 09:00
15

First zip or gzip the folders:
Use the following command:

zip -r NameYouWantForZipFile.zip foldertozip/

or

tar -pvczf BackUpDirectory.tar.gz /path/to/directory

for gzip compression use SCP:

scp username@yourserver.com:~/serverpath/public_html ~/Desktop

ethrbunny
  • 10,379
  • 9
  • 69
  • 131
Sam
  • 159
  • 1
  • 2
1

You may also want to look at rsync if you're doing a lot of files.

If you're going to making a lot of changes and want to keep your directories and files in sync, you may want to use a version control system like Subversion or Git. See http://xoa.petdance.com/How_to:_Keep_your_home_directory_in_Subversion

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
  • 1
    Thanks @Andy, we are using SVN here at work but I just got a new computer and wanted to learn how to do everything through the command line since the guys prefer that here. I'm learning to love it as well :) – alvincrespo Sep 14 '10 at 17:02