• Linux 学习笔记之超详细基础linux命令 Part 11


    Linux学习笔记之超详细基础linux命令

    by:授客 QQ1033553122

    ---------------------------------接Part 10------------------------------

    tarbzip2配套使用

    方法:tar -cvf tarfile.tar.gz --use=bzip2 file   #注意,tar不能加z选项,否则冲突

    功能:告诉tar使用某种压缩工具压缩归档文件

    例子:

    [root@localhost tmp]tar cvf tarfile.tar.gz --use=bizp2 /etc/*.conf

    ....

     

    例子:使用tar拷贝文件[假设某个目录下包含了from-stuff,to-stuff,在from-stuff中包含了整个树状的文件以及其它很难用

    cp -r精确复制出来的东西,现在要把from-stuff下的完整树状结构复制到to-stuff]

    [root@localhost tmp]# mkdir from-stuff

    [root@localhost tmp]# cd /home

    [root@localhost home]# ls

    laiyu    laiyu2    lost+found

    [root@localhost home]# mkdir to-stuff

    [root@localhost home]# cd /tmp/from-stuff

    [root@localhost  from-stuff ]# ls

    [root@localhost  from-stuff ]# touch file

    [root@localhost  from-stuff ]# tar -cf - . | (cd /home/to-stuff;tar -xvf -)

    ./

    .file

    [root@localhost  from-stuff ]# cd /home/to-stuff

    [root@localhost  from-stuff ]# ls

    file

     

    gzip命令

    方法:gzip [选项] 文件|目录

    功能:压缩/解压缩文件,无选项参数时执行压缩操作,压缩产生扩展名为.gz的压缩文件并删除源文件

    主要选项:

    -d(decompress)   解压缩文件,相当于使用gunzip命令

    -r(recursive)    参数为目录时,按目录结构递归压缩目录的所有文件

    -v(verbose)      显示文件的压缩比例

    -l               查看已压缩文件的相关信息

    例子:采用gzip格式压缩当前目录的所有文件

    [laiyu@localhost ~]$ ls

    Desktop    err    etc         file3     list      Public     Videos

    Documents  err~   etc.tar.gz  file4     Music     Templates

    Downloads  error  file2       file.lnk  Pictures  test

    [laiyu@localhost ~]$ gzip *

    gzip: Desktop is a directory -- ignored

    gzip: Documents is a directory -- ignored

    gzip: Downloads is a directory -- ignored

    gzip: etc is a directory -- ignored

    gzip: etc.tar.gz already has .gz suffix -- unchanged

    gzip: file.lnk: Too many levels of symbolic links

    gzip: Music is a directory -- ignored

    gzip: Pictures is a directory -- ignored

    gzip: Public is a directory -- ignored

    gzip: Templates is a directory -- ignored

    gzip: test is a directory -- ignored

    gzip: Videos is a directory -- ignored

    [laiyu@localhost ~]$ ls

    Desktop    err~.gz   etc         file3.gz  list.gz   Public     Videos

    Documents  err.gz    etc.tar.gz  file4.gz  Music     Templates

    Downloads  error.gz  file2.gz    file.lnk  Pictures  test

    说明:gzip命令没有归档功能。当压缩多个文件时将分别压缩每个文件,使之成为.gz压缩文件。注意gzip不是压缩目录,

    如果遇到目录时就会出现上面的ignored提示,解决方法就是加-r选项。

    说明:一个文件是否能被有效的压缩,要视文件本身的格式和内容而定,例如许多图形文件格式,如gifjpeg都是压缩过的。gzip对这类文

    件几乎没有效果。

    通常能被有效压缩的文件包括普通文本文件,可执行文件,函数库之类的二进制文件。

     

    例子:解压缩.gz文件

    [laiyu@localhost ~]$ gzip -d *

    gzip: Desktop is a directory -- ignored

    gzip: Documents is a directory -- ignored

    gzip: Downloads is a directory -- ignored

    gzip: etc is a directory -- ignored

    gzip: etc.tar.gz: not in gzip format

    gzip: file.lnk: Too many levels of symbolic links

    gzip: Music is a directory -- ignored

    gzip: Pictures is a directory -- ignored

    gzip: Public is a directory -- ignored

    gzip: Templates is a directory -- ignored

    gzip: test is a directory -- ignored

    gzip: Videos is a directory -- ignored

     

    bzip2命令

    方法:bzip2 [选项] 文件

    功能:压缩/解压缩文件。无选项时,执行压缩操作。压缩后产生扩展名为.bz2的压缩文件

    说明:比gzip有更好的压缩效果(平均要好10-20%)

    主要选项:

    -d(decompress)    解压缩文件,相当于使用bunzip

    -v(verbose)    显示文件的压缩比例等信息

    例子:压缩file2文件,并显示压缩比例

    [laiyu@localhost home]$ ls

    file kdkdkd test laiyu

    [laiyu@localhost home]$ bzip2 -v test/

    bzip2:Input file test/ is a directory

    [laiyu@localhost home]$ bzip2 -v file

    bzip2:Can't create output file file.bz2:Permission denied

    [laiyu@localhost home]$ su

    Password:

    [root@localhost home]# bzip2 -v file

       file:            0.908:1,      8.8.14 bits/byte, -10.17% saved,59  in ,65 out

     

    例子:解压缩file.bz2

    [root@localhost home]# bzip2 -d file.bz2

     

    zip命令

    方法:zip [选项] 压缩文件 文件列表

    方法:可将多个文件归档压缩(对比:gzip无归档功能,压缩后直接删除源文件,但是不会删除目录)

    主要选项:

    -m    压缩完成后删除原文件

    -r(recursive)    按目录结构递归压缩目录中的所有文件

    例子:将当前目录下的所有文件压缩为file.zip文件

    [laiyu@localhost ~]$ zip file.zip *

      adding: Desktop/ (stored 0%)

      adding: Documents/ (stored 0%)

      adding: Downloads/ (stored 0%)

      adding: err (stored 0%)

      adding: err~ (stored 0%)

      adding: error (stored 0%)

      adding: etc/ (stored 0%)

      adding: etc.tar.gz (deflated 74%)

      adding: file2 (deflated 11%)

      adding: file3 (deflated 46%)

      adding: file4 (deflated 60%)

      adding: file.lnk (deflated 8%)

      adding: list (deflated 11%)

      adding: Music/ (stored 0%)

      adding: Pictures/ (stored 0%)

      adding: Public/ (stored 0%)

      adding: Templates/ (stored 0%)

      adding: test/ (stored 0%)

      adding: Videos/ (stored 0%)

    [laiyu@localhost ~]$ ls

    Desktop    err    etc         file3     file.zip  Pictures   test

    Documents  err~   etc.tar.gz  file4     list      Public     Videos

    Downloads  error  file2       file.lnk  Music     Templates

    说明:zip命令压缩文件过程中将显示每个文件的压缩比例,默认不删除源文件

     

    unzip命令

    方法:unzip [选项] 压缩文件

    功能:解压缩扩展名为.zip的压缩文件

    主要选项:

    -l(list)    查看压缩文件包含的文件

    -t(test)    测试压缩文件是否已损坏

    -d(directory)  目录    指定解压的目标文件

    -n(no)    不覆盖同名文件

    -o    强制覆盖同名文件

    例子:查看file.zip中的文件

    [laiyu@localhost ~]$ unzip -l file.zip

    Archive:  file.zip

      Length      Date    Time    Name

    ---------  ---------- -----   ----

            0  11-20-2012 21:29   Desktop/

            0  11-12-2012 23:11   Documents/

            0  11-01-2012 22:54   Downloads/

           27  11-18-2012 22:50   err

           48  11-14-2012 22:18   err~

           27  11-18-2012 22:48   error

            0  11-11-2012 22:43   etc/

       133120  11-19-2012 22:44   etc.tar.gz

           27  11-14-2012 22:11   file2

           54  11-14-2012 22:11   file3

          127  11-14-2012 23:09   file4

           50  11-13-2012 23:17   file.lnk

           81  11-14-2012 22:04   list

            0  09-23-2012 07:07   Music/

            0  09-23-2012 07:07   Pictures/

            0  09-23-2012 07:07   Public/

            0  09-23-2012 07:07   Templates/

            0  11-19-2012 22:56   test/

            0  09-23-2012 07:07   Videos/

    ---------                     -------

       133561                     19 files

     

    例子:新建file目录,并将file.zip文件的内容解压缩到此目录

    [laiyu@localhost ~]$ mkdir file

    [laiyu@localhost ~]$ unzip -d file file.zip

    Archive:  file.zip

       creating: file/Desktop/

       creating: file/Documents/

       creating: file/Downloads/

     extracting: file/err               

     extracting: file/err~              

     extracting: file/error             

       creating: file/etc/

      inflating: file/etc.tar.gz        

      inflating: file/file2             

      inflating: file/file3             

      inflating: file/file4             

      inflating: file/file.lnk          

      inflating: file/list              

       creating: file/Music/

       creating: file/Pictures/

       creating: file/Public/

       creating: file/Templates/

       creating: file/test/

       creating: file/Videos/

    备注:可以不事先创建file目录,直接解压

    RPM软件包管理

    管理RPM软件包的Shell命令

    安装RPM软件包

    格式:rpm -i[选项] 软件包文件

    功能:安装RPM软件包

    主要选项说明:

    -v(verbose) 显示安装过程

    -h(hash) 显示“#”符号来反应安装的进度。

    --repalcepkgs 重复安装软件包

    例:安装vsftpd软件包

    [laiyu@localhost Downloads]$ rpm -ivh vsftpd-2.0.5-16.el5_4.1.i386.rpm

    warning: vsftpd-2.0.5-16.el5_4.1.i386.rpm: Header V3 DSA/SHA1 Signature, key ID 37017186: NOKEY

    error: Failed dependencies:

        libcap.so.1 is needed by vsftpd-2.0.5-16.el5_4.1.i386

        libcrypto.so.6 is needed by vsftpd-2.0.5-16.el5_4.1.i386

        libssl.so.6 is needed by vsftpd-2.0.5-16.el5_4.1.i386

     

    方法:rpm -U[选项] 软件包文件

    功能:升级RPM软件包。如果当前系统中未安装指定的RPM软件包则直接安装

    主要选项:

    -v(verbose) 显示升级过程

    -h(hash) 显示“#”符号来反映升级的进度

    说明:软件升级后,旧版本的设置文件将被保存。

    例子:升级vsftpd软件包

    [laiyu@localhost Downloads]$ rpm -U vsftpd-2.0.5-16.el5_4.1.i386.rpm

     

     

    方法1rpm -q[选项] 软件包

    主要选项:

    -l(list) 查询已安装软件包所包含的所有文件

    -i(info) 这个命令显示软件包的详细信息,包括:名字,版本以及软件的描述。

    方法2:rpm -q[选项] 文件名

    主要选项:

    -f(file) 查询给定文件属于哪个已安装软件包

     

    方法3rpm -q[选项]

    主要选项:

    -a(all) 查询所有已安装软件包

    功能:查询软件包的相关信息

    例:查询已经安装的fcitx软件包的详细信息

    [laiyu@localhost Downloads]$ rpm -qi fcitx-4.0.0_all.tar.rar

    package fcitx-4.0.0_all.tar.rar is not installed

     

    例子:查询系统中是否已安装软件包samba

    [laiyu@localhost ~]$ rpm -qa | grep samba

    samba-common-3.5.10-125.el6.i686

    samba-winbind-clients-3.5.10-125.el6.i686

    samba-client-3.5.10-125.el6.i686


  • 相关阅读:
    FORTRAN学习记录
    Ubuntu查看和自动挂载硬盘
    正则表达式批量重命名
    [USACO 09FEB]Fair Shuttle
    [ZJOI 2012]灾难
    [BJOI 2010]次小生成树Tree
    Python开发 第一篇 python的前世今生
    关于pycharm字体大小的调整
    关于"人工智能Python""系统环境变量设置步骤
    [洛谷P1168]中位数
  • 原文地址:https://www.cnblogs.com/shouke/p/10158176.html
Copyright © 2020-2023  润新知