9

I'm really new to the command line and Ubuntu and I have recently learned that there is the scp command as well as the cp command. I tried to use an scp command to move a directory from Point A to Point B, but it didn't work. However, when I used cp, it worked just fine.

What is the difference between the two and how do I determine when to use one over the other?

18

TL;DR Read the man pages:

man scp
man cp

From man scp

NAME
     scp — secure copy (remote file copy program)

SYNOPSIS
     scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 ...
         [[user@]host2:]file2

DESCRIPTION
     scp copies files between hosts on a network.  It uses ssh(1) for data transfer, and uses the same authentication and provides the same security
     as ssh(1).  scp will ask for passwords or passphrases if they are needed for authentication.

     File names may contain a user and host specification to indicate that the file is to be copied to/from that host.  Local file names can be made
     explicit using absolute or relative pathnames to avoid scp treating file names containing ‘:’ as host specifiers.  Copies between two remote
     hosts are also permitted.

from man cp

NAME
       cp - copy files and directories

SYNOPSIS
       cp [OPTION]... [-T] SOURCE DEST
       cp [OPTION]... SOURCE... DIRECTORY
       cp [OPTION]... -t DIRECTORY SOURCE...

DESCRIPTION
       Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

       Mandatory arguments to long options are mandatory for short options too.
  • 5
    Well. I feel dumb. I totally forgot about the man pages. Thanks! – BDD Jul 8 '15 at 13:23
15

scp is really for remote copying over SSH. Eg:

scp /path/to/local/file user@server:/path/to/target/dir/
7

scp or Secure Copy is primarily used to copy between a local host and remote host, or two remote hosts, via ssh

The cp command is for copying files locally, i.e. within your host's system.

The man pages that muru has linked in comments should help you understand usage, but there are many tutorials on that internet thing too.

3

You should also learn that there is a man command. Try it! man cp, man scp, man man.

man cp starts out:

    NAME
       cp - copy files and directories

SYNOPSIS
       cp [OPTION]... [-T] SOURCE DEST
       cp [OPTION]... SOURCE... DIRECTORY
       cp [OPTION]... -t DIRECTORY SOURCE...

DESCRIPTION
       Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

and man scp begins with:

    NAME
     scp — secure copy (remote file copy program)

SYNOPSIS
     scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 ... [[user@]host2:]file2

DESCRIPTION
     scp copies files between hosts on a network.  It uses ssh(1) for data transfer, and uses the same authentication and provides the same security as     ssh(1).  Unlike rcp(1), scp will
     ask for passwords or passphrases if they are needed for authentication.
-2

If you have spaces in filenames, scp handles them more nicely than cp, so I often use it even for copying on my local machine for that reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.