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

by:授客 QQ1033553122

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

tar与bzip2配套使用

方法: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选项。

说明:一个文件是否能被有效的压缩,要视文件本身的格式和内容而定,例如许多图形文件格式,如gif,jpeg都是压缩过的。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

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


11-20-2012 21:29  
Desktop/


11-12-2012 23:11  
Documents/


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


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


09-23-2012 07:07  
Music/


09-23-2012 07:07  
Pictures/


09-23-2012 07:07   Public/


09-23-2012 07:07  
Templates/


11-19-2012 22:56  
test/


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

方法1:rpm
-q[选项]

软件包

主要选项:

-l(list)

查询已安装软件包所包含的所有文件

-i(info)

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

方法2:rpm
-q[选项]

文件名

主要选项:

-f(file)

查询给定文件属于哪个已安装软件包

方法3:rpm
-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

Linux 学习笔记之超详细基础linux命令 Part 11的更多相关文章

  1. Linux 学习笔记之超详细基础linux命令(the end)

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 14---------------- ...

  2. Linux 学习笔记之超详细基础linux命令 Part 14

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 13---------------- ...

  3. Linux 学习笔记之超详细基础linux命令 Part 13

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 12---------------- ...

  4. Linux 学习笔记之超详细基础linux命令 Part 12

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 11---------------- ...

  5. Linux 学习笔记之超详细基础linux命令 Part 10

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 9----------------- ...

  6. Linux 学习笔记之超详细基础linux命令 Part 9

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 8----------------- ...

  7. Linux 学习笔记之超详细基础linux命令 Part 8

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 7----------------- ...

  8. Linux 学习笔记之超详细基础linux命令 Part 7

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 6----------------- ...

  9. Linux 学习笔记之超详细基础linux命令 Part 6

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 5----------------- ...

随机推荐

  1. JavaScripts中关于数字的精确计算方法

    问题描述: 37.5*5.5=206.08 (JS算出来是这样的一个结果,我四舍五入取两位小数) ,我先怀疑是四舍五入的问题,就直接用JS算了一个结果为:206.08499999999998 怎么会这 ...

  2. [Swift]LaunchScreen.storyboard如何跳转到到Main.storyboard

    在加载App时,首先读取[LaunchScreen.storyboard]中的内容, 在App加载到内存之后,自动读取[Main.storyboard]中的初始视图控制器, 用于替换原来的[Launc ...

  3. Spring Boot实现热部署

    在Spring Boot实现代码热部署是一件很简单的事情,代码的修改可以自动部署并重新热启动项目. 引用devtools依赖 <dependency> <groupId>org ...

  4. HoloLens开发手记 - 使用配件 Working with accessories

    HoloLens提供了通过蓝牙使用配件的能力.使用附件两种常见情况是用来点击手势和虚拟键盘.对本文来讲,两个最常见的配件就是HoloLens Clicker(点击器)和蓝牙键盘.HoloLens包含了 ...

  5. Python进程-理论

    进程定义 程序: 计算机程序是存储在磁盘上的可执行二进制(或其他类型)文件.只有把它们加载到内存中,并被操作系统调用,它们才会拥有其自己的生命周期. 进程: 进程则是表示的一个正在执行的程序.每个进程 ...

  6. python 离散序列 样本数伸缩(原创)

    解决问题: 有一个固定长度的1维矩阵,将这个矩阵的取样点进行扩充和减少 功能函数: def discrete_scale(data, num): import numpy as np import c ...

  7. QC内部分享ppt

    Quality Center是一个基于Web的测试管理工具,可以组织和管理应用程序测试流程的所有阶段,包括制定测试需求.计划测试.执行测试和跟踪缺陷.此外,通过Quality Center还可以创建报 ...

  8. 喜大普奔,SITE4J网站上线啦

    喜大普奔,SITE4J网站上线啦: 你懂的:https://peterchenhdu.club/

  9. salesforce零基础学习(九十)项目中的零碎知识点小总结(三)

    本次的内容其实大部分人都遇到过,也知道解决方案.但是因为没有牢记于心,导致问题再次出现还是花费了一点时间去排查了原因.在此记录下来,好记性不如烂笔头,争取下次发现类似的现象可以直接就知道原因.废话少说 ...

  10. 深度学习论文翻译解析(二):An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application to Scene Text Recognition

    论文标题:An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application ...