Linux

SCP Command Examples In Linux [ Beginner’s Guide ]

SCP Command Examples In Linux [ Beginner's Guide ]

Insight: SCP Command Examples In Linux [ Beginner’s Guide ]

SCP command is used to securely copy files or folders in Linux. It is used to transfer between remote hosts. It won’t use FTP session during the transfer process. It uses SSH to move data.

Syntax:

scp [options] username1@source_host:directory1/omgfoss.txt username2@destination_host:directory2/filename2

username1@source_host:directory1/omgfoss.txt is the location of the source file. username1 is the name of an user account on the host computer. source_host is the hostname of the source destination. directory1 is the directory where the file omgfoss.txt is located.

The location to which the source file will be copied is: username2@destination_host:directory2/omgfoss.txt
 

SCP Command Examples In Linux

Run the following command in terminal to run to copy file from local host to remote host:

$ scp omgfoss.txt username@destination_host:/remote/directory/

Run the following command to copy file from a remote host to local host :

$ scp username@from_host:omgfoss.txt /local/directory/

Run the following command to copy directory from a remote host to local host :

$ scp -r username@from_host:/remote/directory/  /local/directory/

Run the following command to copy directory from local host to a remote host:

$ scp -r /local/directory/ username@destinationhost:/remote/directory/

Run the following command to opy file from remote host to remote host:

$ scp username@from_host:/remote/directory/file.txt username@destinationhost:/remote/directory/

Important Note: scp command will replace the contents of the target file while copying a source file to a target file which already exists.

Let us know if there is any error in this article.

 



READ THIS ALSO  Happy Birthday Linux : 27 Years Of Freedom

Subscribe To Our Newsletter.

Join our mailing list to receive the latest linux tutorials, tips & tricks, freebies,news and updates from our team.

You have Successfully Subscribed!