15 Linux scp command examples mind-blowing

By | February 11, 2017

scp means secure copy.scp is used to copy file’s across hosts without using any other third party tools.I have used “winscp” without knowing the benefit of “scp”.Once,i have started using “scp”,i never look back for transferring the files across hosts.

Scp command will be installed with basic Linux OS installation.Along with SSH,it comes as free.

15 linux scp command examples awesome

 15 linux scp command examples awesome

Example 1: Simple command “scp” usage.

[ SLTMachine: ] # scp /tmp/sourcecopy.txt /tmp/destinationpath.txt

Here,i am using the scp command to copy file from local machine location to “local machine path
only”.

Example 2: Simple command “scp” usage over different hosts

[ SLTMachine: ] # scp /tmp/sourcecopy.txt [email protected]:/tmp

Here,i am using the scp command to copy file from local machine location to “remote machine path” with the user “root” and to the location of “/tmp”.

Example 3: Transfer file using scp from one local machine to remote location

[ SLTMachine: ] # scp /tmp/sourcecopy.txt [email protected]:/tmp

Here,i am using the scp command to copy file from local machine location to “remote machine path” with the user “root” and to the location of “/tmp” on the remote server called “255.255.255.8”

Example 4: Transfer file using scp from remote machine to local machine

[ SLTMachine: ] # scp [email protected]:/tmp/remotefile.xt /tmp

Here,i am using the scp command to copy file from “remote machine path” with the user “root” and to the location of “/tmp” on the location.

Example 5: I want to know the progress of the scp, while it is doing copy.

[ SLTMachine: ] # scp -v [email protected]:/tmp/remotefile.xt /tmp

Here,i am using the scp command to copy file from “remote machine path” with the user “root” and to the location of “/tmp” on my location.

When we provide the option “-v” option,it will show you the progress of the copy.

Example 6: I want to compress the progress of the scp, while it is doing copy.So,that it will copy faster.

[ SLTMachine: ] # scp -c [email protected]:/tmp/remotefile.xt /tmp

Here,i am using the scp command to copy file from “remote machine path” with the user “root” and to the location of “/tmp” on my current location.

When we provide the option “-c” option,it will  compress the file and copy it to target location.It will make more progress.

Example 7:How to transfer multiple files to the destination server from local server.

[ SLTMachine: ] # scp /tmp/*.log [email protected]:/tmp

With the above command,i am trying to copy the *.log files from current machine /tmp/ to the target machine “255.255.255.8” at the location “/tmp”

Example 8:How to copy entire directory to the destination server.

[ SLTMachine: ] # scp -r  -v /tmp [email protected]:/tmp

With the option “-r”,i am trying to copy the entire directory “/tmp” to the target location of “255.255.255.8:/tmp”

Example 9:How to copy from “remote server” to another “remote server”.

[ SLTMachine: ] # scp [email protected]:/tmp/copyfile.txt [email protected]:/tmp

I am trying to copy file “copyfile.txt” from server “255.255.255.8:/tmp” to “255.255.255.4:/tmp” location from third server.It is something like doing activitiy among 3 servers.

Example 10: In all the above examples,we have to provide the password before we proceed scp copy.It can be avoided,by using “Public and private Key exchange” between hosts.

Example 11: How to control the bandwidth used by scp for transfer.

[ SLTMachine: ] # scp  -l 400 mysourcefile [email protected]:/root/Downloads

“-l” option is used to mention the speed in kbit/second.So,i am mentioning the speed 400 kbit/second.

Example 12: By Default scp uses port number 22,suppose it is running on different port number.

[ SLTMachine: ] # scp  -p 2343 mysourcefile [email protected]:/root/Downloads

I am trying to transfer the file on the port number 2343 instead of default port number 22.

Example 13: I want my copy to the other server without any Progress details ( silent mode )

[ SLTMachine: ] # scp  -q mysourcefile [email protected]:/root/Downloads

With the option “-q”,i am transferring the data in quiet mode to the “192.168.1.3:/root/Downloads”.So,we can not determine how much copy it has done in the progress.

Example 14: cipher change,to change the encryption.

[ SLTMachine: ] # scp  -c blowfish mysourcefile [email protected]:/root/Downloads

By Default,it uses encryption “Triple-DES cipher” to encrypt the data. By Using “-c” option,we can change the encryption to “blowfish”.

Example 15: Preserve File Attributes.

[ SLTMachine: ] # scp  -p mysourcefile [email protected]:/root/Downloads

With the option “-p” ,scp would preserve modification times, access times, and modes from the original file “mysourcefile” to the target copy created at “[email protected]:/root/Downloads”.

Thanks for reading the article on the “SCP” command.If you like it,please share it with others.If you want to add any new usage,please let me know in the comments section.i will add it here.Let everyone benefit out of it.

Please like us on “facebook,twitter,google+”

The following two tabs change content below.

SRINIVAS DARIPELLI

Myself SRINIVAS DARIPELLI. I have 15+ Years of Experience in Programming worked on multiple technologies.Apart from it,I am a blogger, writer, editor, artist and dad 🙂 .I believe in reality.I love to share the Helpful things around the Technology. Feel free to connect with me

Leave a Reply