RHEL7-文件的归档和压缩

本节所讲内容:

文件归档命令tar

压缩命令

 

tar命令

作用:打包、压缩文件

[root@localhost ~]# tar --help

Usage: tar [OPTION...] [FILE]...

GNU `tar' saves many files together into a single tape or disk archive, and can

restore individual files from the archive.

 

Examples:

  tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.

  tar -tvf archive.tar # List all files in archive.tar verbosely.

  tar -xf archive.tar # Extract all files from archive.tar.

 

打包

[root@localhost ~]# tar cvf grub2.tar /boot/grub2/

# c create 创建

#v 详细

#f filename

 

file命令

作用确定文件类型

语法:file 文件名

 

注:linux系统不根据后缀名识别文件类型

用file命令查看文件的类型。

 

[root@localhost ~]# file a.txt

a.txt: POSIX tar archive (GNU)

[root@localhost ~]# file /etc/passwd

/etc/passwd: ASCII text

 

例:把两个目录或目标+文件打包成一个软件包

[root@localhost ~]# tar cvf ss.tar /boot/ /etc/passwd

 

不解包,查看tar中的内容:

[root@localhost ~]# tar tvf grub2.tar

 

解包:

[root@localhost ~]# tar xvf grub2.tar

 

指定解压路径:

[root@localhost ~]# tar xvf grub2.tar -C /opt/

 

对比文件的大小

[root@localhost ~]# du -sh /boot/grub2/

8.1M /boot/grub2/

[root@localhost ~]# ll -h grub2.tar

-rw-r--r-- 1 root root 7.7M Feb 17 07:40 grub2.tar

 

tar 归档 + 压缩

格式文件名格式): .tar.gz 或 .tgz

语法格式:tar zcvf newfile.tar.gz SOURCE

压缩

[root@localhost ~]# tar zcvf grub2.tar.gz /boot/grub2/

 

对比大小

[root@localhost ~]# ll -h grub2.tar*

-rw-r--r-- 1 root root 7.7M Feb 17 07:40 grub2.tar

-rw-r--r-- 1 root root 3.1M Feb 17 07:56 grub2.tar.gz

 

解压

[root@localhost ~]# tar zxvf grub2.tar.gz -C /opt/

 

归档+压缩 :bz2

格式文件名格式): .tar.bz2

语法格式:tar jcvf newfile.tar.gz SOURCE

压缩:

[root@localhost ~]# tar jcvf grub2.tar.bz2 /boot/grub2/

 

对比大小

[root@localhost ~]# ll -h grub2.tar*

-rw-r--r-- 1 root root 7.7M Feb 17 07:40 grub2.tar

-rw-r--r-- 1 root root 2.5M Feb 17 08:02 grub2.tar.bz2

-rw-r--r-- 1 root root 3.1M Feb 17 07:56 grub2.tar.gz

 

解压

[root@localhost ~]# tar jxvf grub2.tar.bz2 -C /opt/

 

zip软件包解压缩命令:

zip是压缩程序,unzip是解压程序。

压缩文件

[root@localhost ~]# zip passwd.zip /etc/passwd

-r 压缩目录

[root@localhost ~]# zip -r grub2.zip /boot/grub2/

[root@localhost ~]# ll -h grub2.*

-rw-r--r-- 1 root root 7.7M Feb 17 07:40 grub2.tar

-rw-r--r-- 1 root root 2.5M Feb 17 08:02 grub2.tar.bz2

-rw-r--r-- 1 root root 3.1M Feb 17 07:56 grub2.tar.gz

-rw-r--r-- 1 root root 3.2M Feb 17 08:11 grub2.zip

 

解压

[root@localhost ~]# unzip grub2.zip -d /opt/

 

任务Linux系统能不能解压rar格式的压缩包话,如何解压?

 

补充:

压缩命令gzip bzip2 xz

语法格式

gzip 文件

bzip2 文件

xz 文件

 

解压

gzip -d 文件

bzip2 -d 文件

xz -d 文件 或 unxz 文件

不解压情况查看压缩文件内容分别用zcat bzcat xzcat

 

特点:只能对文件进行压缩,且压缩后源文件消失(其中xz命令可以加上-k参数保留源文件)

 

 

进程管理:

pstree

程序与进程:

程序是静态的(文件),进程是动态的(运行的程序)。

 

进程和线程:

一个程序至少有一个进程,一个进程至少有一个线程.
进程之间内存是独立

线程之前内存共享 ,高并发好一些 。 安全性差一些。

 

[root@localhost ~]# pstree -p | more

systemd(1)-+-ModemManager(1038)-+-{ModemManager}(1083)

  | `-{ModemManager}(1085)

  |-NetworkManager(1033)-+-{NetworkManager}(1096)

  | `-{NetworkManager}(1111)

 

tree

显示目录树形结构

[root@localhost ~]# rpm -ivh /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm

[root@localhost ~]# tree /etc/default/

/etc/default/

├── grub

├── nss

└── useradd

 

0 directories, 3 files

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值