linux基础命令_压缩挂载

蛋蛋 2022年09月14日 37 0

tar

压缩和解压缩命令
tar命令选项:

-c 创建打包文件
-v 显示打包或者解包的详细信息
-f 指定文件名称, 必须放到所有选项后面
-z 压缩或解压缩(.gz)
-j 压缩或解压缩(.bz2)
-x 解包
-C 解压缩到指定目录
-t 只看包内容,不解压

  • .tar
tar xvf FileName.tar  #解包
tar cvf FileName.tar DirName  #打包
  • .tar.gz
tar zxvf FileName.tar.gz  #解包
tar zcvf FileName.tar.gz DirName  #打包
  • .tar.bz2
tar jxvf FileName.tar.bz2  #解包
tar jcvf FileName.tar.bz2 DirName  #打包
  • .tar.bz
tar jxvf FileName.tar.bz  #解包
    #打包
  • .tar.Z
tar Zxvf FileName.tar.Z  #解包
tar Zcvf FileName.tar.Z DirName  #打包
  • .tgz
tar zxvf test.tgz -C path  #解包
tar zxvf FileName.tgz  #打包
tar czvf FileName.tgz path  #打包
  • .lzma
tar xfv test.tar.lzma --lzma -C path  #解包
tar cfv test.tar.lzma test3/ -lzma  #打包

zip

-r 参数表示递归打包包含子目录的全部内容
-q 参数表示为安静模式,即不向屏幕输出信息
-o 表示输出文件,需在其后紧跟打包输出文件名
-e 参数可以创建加密压缩包

zip -r myfile.zip ./*
zip OpenEuler2203.zip OpenEuler2203.iso

unzip

-o:不提示的情况下覆盖文件;
-l:不解压看zip包的内容
-d:-d /home/sunny指明将文件解压缩到/home/sunny目录下

# unzip -l test.zip
Archive:  test.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
1068466176  11-17-2021 19:32   test.iso
---------                     -------
1068466176                     1 file
unzip -o -d /home/sunny myfile.zip

报错

Archive:  curl.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of curl.zip or
        curl.zip.zip, and cannot find curl.zip.ZIP, period.

-->报这种错误说明在文件上传或下载的过程中出现了文件丢失的情况,需要使用sftp或scp重新上传文件到服务器,然后使用unzip命令或jar命令解压压缩文件

rpm

rpm -qpl a.rpm  #只看包内容

bzip2

bzip2 -d FileName.bz  #解包

bunzip2

bunzip2 FileName.bz  #解包

uncompress

uncompress FileName.Z  #解包

compress

compress FileName  #打包

gunzip

gunzip 是个使用广泛的解压缩程序,它用于解开被 gzip 压缩过的文件,这些压缩文件预设最后的扩展名为 .gz。事实上 gunzip 就是 gzip 的硬连接,因此不论是压缩或解压缩,都可通过 gzip 指令单独完成。

-a或--ascii  使用ASCII文字模式。
-c或--stdout或--to-stdout  把解压后的文件输出到标准输出设备。
-f或-force  强行解开压缩文件,不理会文件名称或硬连接是否存在以及该文件是否为符号连接。
-h或--help  在线帮助。
-k或--keep  保留原始压缩文件。
-l或--list  列出压缩文件的相关信息。
-L或--license  显示版本与版权信息。
-n或--no-name  解压缩时,若压缩文件内含有远来的文件名称及时间戳记,则将其忽略不予处理。
-N或--name  解压缩时,若压缩文件内含有原来的文件名称及时间戳记,则将其回存到解开的文件上。
-q或--quiet  不显示警告信息。
-r或--recursive  递归处理,将指定目录下的所有文件及子目录一并处理。
-S<压缩字尾字符串>或--suffix<压缩字尾字符串>  更改压缩字尾字符串。
-t或--test  测试压缩文件是否正确无误。
-v或--verbose  显示指令执行过程。
-V或--version 显示版本信息。

gunzip ab.gz

gzip

gzip -d FileName.gz  #解包
gzip FileName  #打包

xz

Linux常用命令xz命令 XZ Utils 是为 POSIX 平台开发具有高压缩率的工具。它使用 LZMA2 压缩算法,生成的压缩文件比 POSIX 平台传统使用的 gzip、bzip2 生成的压缩文件更小,而且解压缩速度也很快。
红帽(Red Hat)从Enterprise Server 6.2 开始,启动镜像文件initrd.img 开始改用xz 工具进行压缩。

-z, --compress force compression 强行执行压缩
-d, --decompress, --uncompress 强行执行解压缩
-t, --test test compressed file integrity 测试压缩文件的完整性
-l, --list list information about .xz files 列出压缩文件的信息
-k, --keep keep (don't delete) input files 保留原文件不要删除
-f, --force force overwrite of output file and (de)compress links 强制覆盖输出文件和压缩链接
-c, --stdout, --to-stdout 写入标准输出,不要删除输入文件
-0 ... -9 压缩预设:默认为6;取压缩机,使用7-9之前解压缩考虑内存使用量!
-v, --verbose be verbose; specify twice for even more verbose 显示更详细的信息
-V, --version display the version number and exit 版本信息
-e, --extreme try to improve compression ratio by using more CPU time;
does not affect decompressor memory requirements 尝试通过使用更多的CPU时间来提高压缩比; 要求不影响解压缩存储器

  • 查看initrd.img格式并解压initrd.img文件
    XZ格式
# file initrd.img
initrd.img: XZ compressed data
# cd initrd
# xz  -dc isolinux/initrd.img | cpio -id
# ls
bin  dev  etc  init  lib  lib64  proc  root  run  sbin  shutdown  sys  sysroot  tmp  usr  var

注:会解压到当前目录
initrd.img解压完成,就是一个完整的/目录

LZMA格式

# file initrd.img
initrd.img: LZMAcompressed data, streamed
cd initrd
cp /path/to/initrd.img .
# 解压文件
## 如果直接是 LZMA 格式
lzma -d < initrd.img > uncompressed-initrd

## 如果是 LZMA 压缩带内核文件,需先转换
xz --format=lzma --decompress --stdout < initrd.img > uncompressed-initrd

# 提取文件内容
mkdir extracted
cd extracted
cpio -idmv < ../uncompressed-initrd
  • 压缩initrd.img文件
# find . | cpio -c -o | xz -9 --format=lzma > initrd.img

在当前目录下生成initrd.img文件,--force 可以设置压缩的格式,由于LZMA具有优秀的压缩率及占用资源少的特点,越来越多的工具采用lzma进行打包,后缀名为:tar.lzma。

rpm2cpio

linux提取rpm包,不安装提取rpm包里的文件

rpm2cpio nginx-1.2.0-0.x86_64.rpm |cpio -dimv

mount

挂载光盘镜像

mount -o loop filename.iso /mnt/cdrom

vmlinuz文件解压缩(待实操)

https://www.icode9.com/content-4-1182132.html

initrd.img

https://blog.csdn.net/qq_28693567/article/details/105359749

xz -dc ../initrd.img | cpio -id

关于initrd.img的压缩(制作)及解压的过程

https://blog.csdn.net/qq_38428855/article/details/101779147
https://www.cnblogs.com/klb561/p/9147577.html

# file initrd.img
initrd.img: gzip compressed data, from Unix, max compression
# mv initrd.img initrd.img.gz
# gunzip initrd.img.gz
# file initrd.img
initrd.img: ASCII cpio archive (SVR4 with no CRC)
# mkdir initrd_extracted
# cd initrd_extracted
# cpio -idmv < ../initrd.img
# file initrd.img
initrd.img: gzip compressed data, from Unix, last modified: Thu Jul 28 18:01:52 2022, max compression

参考:
https://blog.csdn.net/weixin_34388311/article/details/116559318
https://blog.csdn.net/qq_28693567/article/details/105359749

Last Updated: 2025/05/21 15:06:28
抓包工具_wireshark [转]JSON常见用法:json.load()、json.loads()、json.dump()、json.dumps()