Linux commands scp and tar

Copy foo.txt and bar.txt in the current directory from the local to the remote:

1
scp  foo.txt bar.txt username@remotehost: /path/directory/

Copy foo.txt and bar.txt from the remote back to the local current directory:

1
scp  username@remotehost: /path/directory/ \{foo.txt,bar.txt\} .

scp报错:host key verification failed

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @ 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! 
Someone could be eavesdropping on you right now (man-in-the-middle attack)! 
It is also possible that the RSA host key has just been changed. 
The fingerprint for the RSA key sent by the remote host is 
xxxxx. 
Please contact your system administrator. 
Add correct host key in /root/.ssh/known_hosts to get rid of this message. 
Offending key in /root/.ssh/known_hosts:20 
RSA host key for 10.xx.xx.12 has changed and you have requested strict checking. 
Host key verification failed. 

Solution:

cd /root/.ssh

vim known_hsots

Delete the corresponding ip and key



tar command

 [root@linux ~]# tar [-cxtzjvfpPN] Files and directories...

parameter

-c: Parameter command to create a compressed file (create meaning);
-x: Unpack the parameter command of a compressed file!
-t: View the files in the tarfile!
Pay special attention to the fact that only one c/x/t can exist in the parameter release! Cannot exist at the same time! Because it is impossible to compress and decompress at the same time.
-z: Does it also have the attributes of gzip? That is, do you need to use gzip compression?
-j: Does it also have the attributes of bzip2? That is, do you need to use bzip2 compression?
-v: show files during compression! This is commonly used, but not recommended for background execution!
-f: Use the file name, please pay attention, you must immediately pick up the file name after f! No more parameters!
For example, using "tar -zcvfP tfile sfile" is a wrong way of writing, it is correct to write "tar -zcvPf tfile sfile"!
-p: Use the original attributes of the original document (the attributes will not change according to the user)
-P: You can use absolute path to compress!
-N: Only the newer date (yyyy/mm/dd) will be packaged into the newly created file!
--exclude FILE: Don't pack FILE during the compression process!

tar

tar is a very widely used document packaging format in Linux. Its advantage is that it only consumes very little CPU and time to pack files, but it is just a packaging tool and is not responsible for compression. Here is how to package a directory:

# tar -cvf archive_name.tar directory_to_compress
   
    
    
  • 1

Here is how to unpack the command:

# tar -xvf archive_name.tar.gz
   
    
    
  • 1

The above unpack command will unpack the file in the current directory. Of course, you can also use this command to change the unpacking path:

# tar -xvf archive_name.tar -C /tmp/extract_here/
   
    
    
  • 1

tar.gz

这种格式是我使用得最多的压缩格式。它在压缩时不会占用太多CPU的,而且可以得到一个非常理想的压缩率。可以使用下面的命令去压缩一个目录:

# tar -zcvf archive_name.tar.gz directory_to_compress
   
    
    
  • 1

解压缩:

# tar -zxvf archive_name.tar.gz
   
    
    
  • 1

上面这个解包命令将会将文档解压在当前目录下面。当然,你也可以用这个命令来更改解包的路径:

# tar -zxvf archive_name.tar.gz -C /tmp/extract_here/
   
    
    
  • 1

tar.bz2

这种压缩格式是我们提到的所有方式中压缩率最好的。当然,这也就意味着,它比前面的方式要占用更多的CPU与时间。下面的命令就是如何使用tar.bz2进行压缩。

# tar -jcvf archive_name.tar.bz2 directory_to_compress
   
    
    
  • 1

上面这个解包命令将会将文档解开在当前目录下面。当然,你也可以用这个命令来更改解包的路径:

# tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/


Guess you like

Origin blog.csdn.net/qq_36961530/article/details/78743058