RHCE——归档文件并在系统间复制文件

来源:互联网 发布:mac设置airdrop 编辑:程序博客网 时间:2024/05/21 19:45

管理压缩的tar存档

  • c(创建存档)
  • t (列出存档内容)
  • x(提取存档文件)
  • f(要操作的文件名)
  • v(详细信息)
    打包文件
[root@localhost text]# tar cfv file_1.tar file1 file2 file3file1file2file3[root@localhost text]# ll file_1.tar -rw-r--r--. 1 root root 10240 8月   1 01:19 file_1.tar

列出tar存档的内容

[root@localhost text]# tar tf file_1.tar file1file2file3

提取存档内容,加P可以同时保留文件权限

[root@localhost text]# tar xpf file_1.tar

创建tar压缩文件

  • z 用于gzip压缩,文件后缀.tar.gz或.tgz
  • j 用于bzip2压缩,文件后缀.tar.bz2
  • J用于xz压缩,文件后缀.tar.xz
[root@localhost text]# tar zcf text1.tar.gz file1 file2[root@localhost text]# tar jcf text1.tar.bz2 file1 file2[root@localhost text]# tar Jcf text1.tar.xz file1 file2[root@localhost text]# ll-rw-r--r--. 1 root root 125 81 01:34 text1.tar.bz2-rw-r--r--. 1 root root 124 81 01:33 text1.tar.gz-rw-r--r--. 1 root root 172 81 01:34 text1.tar.xz//解压[root@localhost text1]#  tar zxf ../../text1.tar.gz [root@localhost text2]#  tar jxf ../../text1.tar.bz2 [root@localhost text3]#  tar Jxf ../../text1.tar.xz 

在系统间安全地复制文件

使用scp协议,根据ssh进行加密传输

[root@localhost text]# scp root@120.24.222.231:~/hyt.tar .root@120.24.222.231's password: hyt.tar                                                                                                             100%   10KB  10.0KB/s   00:00    [root@localhost text]# scp text1.tar.bz2 root@120.24.222.231:~/root@120.24.222.231's password: text1.tar.bz2                                                                                                       100%  125     0.1KB/s   00:00    

使用sftp远程传输文件

[root@localhost text]# sftp 120.24.222.231root@120.24.222.231's password: Connected to 120.24.222.231.sftp> mkdir sftpsftp> cd sftpsftp> put /etc/hohost.conf    hosts        hosts.allow  hosts.deny   sftp> put /etc/hostsUploading /etc/hosts to /root/sftp/hosts/etc/hosts                                                                                                          100%  158     0.2KB/s   00:00    
[student@localhost 桌面]$ sftp root@120.24.222.231root@120.24.222.231's password: Connected to 120.24.222.231.sftp> get ~/aaFile "/root/~/aa" not found.sftp> get aaFetching /root/aa to aa/root/aa                                                                                                            100%   20     0.0KB/s   00:00    sftp> exit 

rsync在系统间安全的同步文件

方法和scp类似

[student@localhost 桌面]$ rsync -av /var/log/messages /tmpsending incremental file listrsync: send_files failed to open "/var/log/messages": Permission denied (13)sent 49 bytes  received 31 bytes  160.00 bytes/sectotal size is 111427  speedup is 1392.84rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9][student@localhost 桌面]$ rsync -av /var/log/messages root@120.24.222.231:/tmproot@120.24.222.231's password: sending incremental file listrsync: send_files failed to open "/var/log/messages": Permission denied (13)sent 49 bytes  received 31 bytes  12.31 bytes/sectotal size is 112130  speedup is 1401.62rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]