What is the difference between scp and cp?
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?
25 Answers
TL;DR Read the man pages:
man scp
man cpFrom 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. 1 scp is really for remote copying over SSH. Eg:
scp /path/to/local/file user@server:/path/to/target/dir/ 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.
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. 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.