Linux命令scp与tar

来源:互联网 发布:管理支撑系统大数据 编辑:程序博客网 时间:2024/04/29 06:27

从本地复制当前目录下的foo.txt和bar.txt到远程:

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

从远程复制foo.txt和bar.txt回本地的当前目录:

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. 

解决方法:

cd /root/.ssh

vim known_hsots

删除对应的ip和密钥



tar命令

 [root@linux ~]# tar [-cxtzjvfpPN] 文件与目录 ....

参数

-c :建立一个压缩文件的参数指令(create 的意思);
-x :解开一个压缩文件的参数指令!
-t :查看 tarfile 里面的文件!
特别注意,在参数的下达中, c/x/t 仅能存在一个!不可同时存在!因为不可能同时压缩与解压缩。
-z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?
-j :是否同时具有 bzip2 的属性?亦即是否需要用 bzip2 压缩?
-v :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程!
-f :使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!
例如使用『 tar -zcvfP tfile sfile』就是错误的写法,要写成『 tar -zcvPf tfile sfile』才对喔!
-p :使用原文件的原来属性(属性不会依据使用者而变)
-P :可以使用绝对路径来压缩!
-N :比后面接的日期(yyyy/mm/dd)还要新的才会被打包进新建的文件中!
--exclude FILE:在压缩的过程中,不要将 FILE 打包!

tar

tar是在Linux中使用得非常广泛的文档打包格式。它的好处就是它只消耗非常少的CPU以及时间去打包文件,但它仅仅只是一个打包工具,并不负责压缩。下面是如何打包一个目录:

# tar -cvf archive_name.tar directory_to_compress
  • 1

下面是如何解包的命令:

# tar -xvf archive_name.tar.gz
  • 1

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

# 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/


原创粉丝点击