鸟哥的linux私房菜学习笔记《十九》压缩、备份、还原和刻录

  1. gzip,zcat

    root@Ubuntu:~# gzip [-cdtv#] 文件名
    root@Ubuntu:~# zcat 文件名.gz

    参数:
    默认不用参数直接压缩
    默认压缩完后删除源文件
    默认解压完后删除源文件
    -c:将压缩的数据输出到屏幕,课通过数据流量重定向来处理
    -d:解压缩的数据
    -t:可以用来检验一个压缩文件的一致性,看看文件有无错误
    -v:可以显示出原文件/压缩文件的压缩比等信息
    -#:压缩等级,-1最快,但是压缩比最差

    
    # 将/etc/manpath.config复制到/tmp中,并且以gzip压缩:
    
    root@Ubuntu:~# cd /tmp
    root@Ubuntu:/tmp# cp /etc/manpath.config .
    root@Ubuntu:/tmp# gzip -v manpath.config 
    manpath.config:  62.3% -- replaced with manpath.config.gz
    root@Ubuntu:/tmp# ll /etc/manpath.config 
    -rw-r--r-- 1 root root 5170 117  2015 /etc/manpath.config
    root@Ubuntu:/tmp# 
    

    cat可以读文件,zcat可以读取纯文本被压缩后的压缩文件

    
    # 由于man.config是文本文件,将压缩文件的内容读出来:
    
    root@Ubuntu:/tmp# zcat manpath.config.gz 
    
    # 将文件解压缩:
    
    root@Ubuntu:/tmp# gzip -9 -c manpath.config.gz > man.config.gz
    -rw-r--r-- 1 root root 2024 38 18:28 man.config.gz
    -rw-r--r-- 1 root root 1983 38 18:25 manpath.config.gz
  2. bzip2,bzcat

    root@Ubuntu:/tmp# bzip2 [-cdkzv#] 文件名
    root@Ubuntu:/tmp# bzip2 文件名.bz2

    参数:
    默认不用参数直接压缩
    默认压缩完后删除源文件
    默认解压完后删除源文件
    -c:将压缩过程产生的数据输出到屏幕上
    -d:解压缩的参数
    -k:保留源文件,而不会删除原始文件
    -z:压缩的参数
    -v:显示源文件/压缩文件的压缩比
    -#:与gzip同样的,都是计算压缩比的参数

    
    # 将/tmp/manpath.config以bzip2压缩:
    
    root@Ubuntu:/tmp# bzip2 -z manpath.config 
    
    # 将man.config.bz2的内容读出来:
    
    root@Ubuntu:/tmp# bzcat manpath.config.bz2 
    
    # 将manpath.config.bz2解压缩:
    
    root@Ubuntu:/tmp# bzip2 -d manpath.config.bz2 
    
    # 将manpath.config用最佳压缩比压缩,并保留原本的文件:
    
    root@Ubuntu:/tmp# bzip2 -9 -c manpath.config > man.config.bz2
  3. tar

    
    # 打包与压缩:
    
    [root@CentOS ~]# tar [-j|-z] [cv] [-f 新建的文件名] filename...
    
    # 查看文件名:
    
    [root@CentOS ~]# tar [-j|-z] [tv] [-f 新建的文件名]
    
    # 解压缩:
    
    [root@CentOS ~]# tar [-f|-z] [xv] [-f 新建的文件名] [-C 目录]
    

    参数:
    -c:新建打包文件,可搭配-v来查看过程中被打包的文件名
    -t:查看打包文件的内容含有哪些文件名
    -x:解压缩或解打包的功能,可以搭配-C在特定目录解开
    特别留意-c,-t,-x不可同时出现在同一串命令行中
    -j:通过bzip2的支持进行压缩/解压缩,文件名最好为*.tar.bz2
    -z:通过gzip的支持进行解压缩,文件名最好为*.tar.gz
    -v:在压缩/解压缩的过程中,将文件名显示出来
    -f filename:后接文件名
    -C 目录:在特定目录解压缩时使用
    -p:保留备份数据的原本权限与属性,常用于备份重要的配置文件
    -P:保留绝对路径,即允许备份数据中含有根目录存在之意
    压缩:tar -jcv -f filename.tar.bz2
    查询:tar -jtv -f filename.tar.bz2
    解压缩:tar -jxv -f filename.tar.bz2 -C 欲解压缩的目录
    使用tar加入-j或-z的参数备份/etc/目录

    
    # 用gzip备份/etc:
    
    [root@CentOS ~]# tar -zpcv -f /root/etc.tar.gz /etc
    [root@CentOS ~]# ll
    -rw-r--r--. 1 root  root  10649317 Mar  8 06:45 etc.tar.gz
    
    # 用bzip2备份/etc:
    
    [root@CentOS ~]# ll
    -rw-r--r--. 1 root  root   9081686 Mar  8 06:47 etc.tar.bz2
    
    # 查看文件名:
    
    [root@CentOS ~]# tar -jtv -f /root/etc.tar.bz2 
    

    如果去掉根目录,假设你讲备份数据在/tmp中解开,那么解压缩的文件名就会变成/tmp/etc/xxx。但是如果没有去掉根目录,解压缩后的文件名就会是绝对路径,即解压缩后的数据一定会被放置在/etc/xxx去。如此一来,原本的/etc/下面的数据就会被覆盖

    
    # 将文件名中的(根)目录备份下来,并查看一下备份文件的内容文件名
    
    [root@CentOS ~]# tar -jpPcv -f /root/etc.and.root.tar.bz2 /etc
    [root@CentOS ~]# tar -jtf /root/etc.and.root.tar.bz2 
    
    # 加上-P参数,文件内的根目录就会存在
    
    
    # 将备份的数据解压缩,并考虑特定目录的解压缩操作(-C参数的应用)
    
    [root@CentOS ~]# tar -jxv -f /root/etc.tar.bz2 
    [root@CentOS ~]# ll
    drwxr-xr-x. 154 root  root     12288 Mar  8 05:50 etc
  4. 仅解开单一文件的方法:

    [root@CentOS ~]# tar -jtv -f /root/etc.tar.bz2 } grep 'shadow'
    tar: }: Not found in archive
    tar: grep: Not found in archive
    tar: shadow: Not found in archive
    tar: Exiting with failure status due to previous errors
    [root@CentOS ~]# tar -jtv -f /root/etc.tar.bz2 | grep 'shadow'
    ---------- root/root      1383 2017-03-01 16:50 etc/shadow-
    ---------- root/root      1375 2017-03-02 05:22 etc/shadow
    ---------- root/root       856 2017-03-01 16:50 etc/gshadow-
    ---------- root/root           867 2017-03-01 16:50 etc/gshadow
    
    # tar -jxv -f 打包文件.tar.bz2 特解开文件名
    
    [root@CentOS ~]# tar -jxv -f /root/etc.tar.bz2 etc/shadow
    etc/shadow
    [root@CentOS ~]# ll etc
    ----------. 1 root root 1375 Mar  2 05:22 etc/shadow
  5. 打包某目录,但不含有该目录下的某些文件的做法:

    
    # 打包/root和/etc这两个重要目录,但却不想打包/root/etc*开头的文件
    
    
    # 假设这个新的文件要放置在/root/system.tar.bz2,当然这个文件不要打包自己(因为这个文件放在/root下面)
    
    [root@CentOS ~]# tar -jcv -f /root/system.tar.bz2 --exclude=/root/etc* --exclude=/root/system.tar.bz2 /etc /root
    
  6. 尽备份比某个时刻新的文件:

    
    # 先由find找出比/etc/passwwwd 还要新的文件:
    
    [root@CentOS ~]# find  /etc -newer /etc/passwd
    [root@CentOS ~]# ll /etc/passwd
    -rw-r--r--. 1 root root 2548 Mar  1 16:50 /etc/passwd
    
    # 使用tar进行打包,,日期为2017/03/07:
    
    [root@CentOS ~]# tar -jcv -f /root/etc.newer.then.passwd.tar.bz2 --newer-mtime="2017.03.07" /etc/*
    
    # 显示文件:
    
    [root@CentOS ~]# tar -jtv -f /root/etc.newer.then.passwd.tar.bz2 > grep -v '/$'
    
  7. 特殊应用:利用管道命令与数据流

    
    # 将/etc整个目录一边打包一边在/tmp中解开
    
    [root@CentOS ~]# cd /tmp/
    [root@CentOS tmp]# tar -cvf - /etc | tar -xvf -
    
    # 这个命令有点像cp -r /etc /tmp
    
  8. 完整备份工具:dump
    参数:
    -S:仅列出后面的待备份数据需要多少磁盘空间才能够备份完毕
    -u:将这次dump的时间记录到/etc/dumpdateS文件中
    -v:将dump的文件过程显示出来
    -j:加入bzip2的支持,将数据进行压缩
    -levle:等级
    -f:有点类似tar,后面接产生的文件
    -W:列出/etc/fatab里面的具有dump设置的分区是否有备份过
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
  9. restore:恢复备份
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
  10. mkisofs:光盘写入工具
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
  11. cdrecord:光盘刻录工具
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述

  12. dd
    这里写图片描述
    这里写图片描述
    这里写图片描述

  13. cpio
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译 ./configure --prefix=/usr/local/php --exec-prefix=/usr/local/php --bindir=/usr/local/php/bin --sbindir=/usr/local/php/sbin --includedir=/usr/local/php/include --libdir=/usr/local/php/lib/php --mandir=/usr/local/php/php/man --with-config-file-path=/usr/local/php/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr /i nclude --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm --enable-fastcgi --with-fpm-user=www --with-fpm-group=www --without-gdbm --with-mcrypt=/usr/local/apps/libmcrypt --disable-fileinfo 报错:1, **configure: error: system libzip must be upgraded to version >=**0.11。 使用Yum最新版只到0.10,不足以达到要求。 一、先删除libzip yum remove libzip -y SSH执行以上命令,先删除libzip 和 libzip-devel 二、下载安装并手动编译 wget https://nih.at/libzip/libzip-1.2.0.tar.gz tar -zxvf libzip-1.2.0.tar.gz cd libzip-1.2.0 ./configure make && make install 三、(可忽略)另外最新版本请参考官网:https://nih.at/libzip/ 1.5.0的libzip需要cmake wget https://libzip.org/download/libzip-1.5.0.tar.gz tar -zxvf libzip-* cd libzip* mkdir build && cd build && cmake .. && make && make install 报错2: error: off_t undefined; check your library configuration 根据报错信息分析 configure: error: off_t undefined; check your library configuration 未定义的类型 off_t。 off_t 类型是在 头文件 unistd.h中定义的,在32位系统 编程成 long int ,64位系统则编译成 long long int ,这里题主的系统应该是 64位的吧,在进行编译的时候 是默认查找64位的动态链接库,但是默认情况下 centos 的动态链接库配置文件/etc/ld.so.conf里并没有加入搜索路径,这个时候需要将 /usr/local/lib64 /usr/lib64 这些针对64位的库文件路径加进去。 采用下面的方法。 添加搜索路径到配置文件 echo '/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64'>>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值