compress & decompression

tar

命令参数详解

1. 下面这五个参数是独立的参数,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个

  • -c: 建立压缩档案
  • -x:解压
  • -t:查看内容
  • -r:向压缩归档文件末尾追加文件
  • -u:更新原压缩包中的文件

2. 下面的参数是根据需要在压缩或解压档案时可选的

  • -z:有gzip属性的
  • -j:有bz2属性的
  • -Z:有compress属性的
  • -v:显示所有过程
  • -O:将文件解开到标准输出

3. 下面的参数是必须的

  • -f: 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名

4. 示例

# tar -cf all.tar *.jpg
这条命令是将所有.jpg的文件打成一个名为all.tar的包。-c是表示产生新的包,-f指定包的文件名。

# tar -rf all.tar *.gif
这条命令是将所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。

# tar -uf all.tar logo.gif
这条命令是更新原来tar包all.tar中logo.gif文件,-u是表示更新文件的意思。

# tar -tf all.tar
这条命令是列出all.tar包中所有文件,-t是列出文件的意思

# tar -xf all.tar
这条命令是解出all.tar包中所有文件,-t是解开的意思

compress

# tar -cvf jpg.tar *.jpg
将目录里所有jpg文件打包成tar.jpg 

# tar -czf jpg.tar.gz *.jpg
将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩,生成一个gzip压缩过的包,命名为jpg.tar.gz

# tar -cjf jpg.tar.bz2 *.jpg
将目录里所有jpg文件打包成jpg.tar后,并且将其用bzip2压缩,生成一个bzip2压缩过的包,命名为jpg.tar.bz2

# tar -cZf jpg.tar.Z *.jpg
将目录里所有jpg文件打包成jpg.tar后,并且将其用compress压缩,生成一个umcompress压缩过的包,命名为jpg.tar.Z

# rar a jpg.rar *.jpg
rar格式的压缩,需要先下载rar for linux

# zip jpg.zip *.jpg
zip格式的压缩,需要先下载zip for linux

decompression

# tar -xvf file.tar
解压 tar包

# tar -xzvf file.tar.gz
解压tar.gz

# tar -xjvf file.tar.bz2
解压 tar.bz2

# tar -xZvf file.tar.Z
解压tar.Z

# unrar e file.rar
解压rar

# unzip file.zip
解压zip

summary

  • *.tar 用 tar -xvf 解压
  • *.gz 用 gzip -d或者gunzip 解压
  • *.tar.gz和*.tgz 用 tar -xzf 解压
  • *.bz2 用 bzip2 -d或者用bunzip2 解压
  • *.tar.bz2用tar -xjf 解压
  • *.Z 用 uncompress 解压
  • *.tar.Z 用tar -xZf 解压
  • *.rar 用 unrar e解压
  • *.zip 用 unzip 解压

zip

参数详解

  • -c:将解压缩的结果
  • -l:显示压缩文件内所包含的文件
  • -p:与-c参数类似,会将解压缩的结果显示到屏幕上,但不会执行任何的转换
  • -t:检查压缩文件是否正确
  • -u:与-f参数类似,但是除了更新现有的文件外,也会将压缩文件中的其它文件解压缩到目录中
  • -v:执行是时显示详细的信息
  • -z:仅显示压缩文件的备注文字
  • -a:对文本文件进行必要的字符转换
  • -b:不要对文本文件进行字符转换
  • -C:压缩文件中的文件名称区分大小写
  • -j:不处理压缩文件中原有的目录路径
  • -L:将压缩文件中的全部文件名改为小写
  • -M:将输出结果送到more程序处理
  • -n:解压缩时不要覆盖原有的文件
  • -o:不必先询问用户,unzip执行后覆盖原有文件
  • -P:使用zip的密码选项
  • -q:执行时不显示任何信息
  • -s:将文件名中的空白字符转换为底线字符
  • -V:保留VMS的文件版本信息
  • -X:解压缩时同时回存文件原来的UID/GID

compress

# zip -r mydata.zip mydata
把/home目录下面的mydata目录压缩为mydata.zip

# zip -r abc123.zip abc 123.txt
把/home目录下面的abc文件夹和123.txt压缩成为abc123.zip

decompression

# unzip mydata.zip -d mydatabak
把/home目录下面的mydata.zip解压到mydatabak目录里面

# unzip wwwroot.zip
把/home目录下面的wwwroot.zip直接解压到/home目录里面

# unzip abc\*.zip
把/home目录下面的abc12.zip、abc23.zip、abc34.zip同时解压到/home目录里面

# unzip -v wwwroot.zip
查看把/home目录下面的wwwroot.zip里面的内容

# unzip -t wwwroot.zip
验证/home目录下面的wwwroot.zip是否完整

# unzip -j wwwroot.zip
把/home目录下面wwwroot.zip里面的所有文件解压到第一级目录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用LIBJPEG库在STM32上进行JPEG图像的解码和编码是比较常见的应用。下面是一个简单的例程,展示如何在STM32上使用LIBJPEG库进行JPEG图像的解码和编码。 首先,需要将LIBJPEG库添加到STM32项目中。可以从LIBJPEG官网下载最新版本的库文件,并将其添加到STM32项目中。在添加库文件时,需要注意将库文件的头文件和源文件都添加到项目中。 接下来,需要编写代码来初始化JPEG解码器和编码器。例如,以下代码初始化了JPEG解码器: ``` /* JPEG decoding object */ jpeg_decompress_struct cinfo; /* Error handler object */ jpeg_error_mgr jerr; /* Initialize the JPEG decompression object with default error handling */ cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); ``` 然后,需要读取JPEG图像文件并将其解码。以下代码展示了如何读取并解码JPEG图像: ``` /* Open the input file */ FILE *infile = fopen("input.jpg", "rb"); if (infile == NULL) { printf("Error opening input file"); return; } /* Specify the input source */ jpeg_stdio_src(&cinfo, infile); /* Read the JPEG header */ jpeg_read_header(&cinfo, TRUE); /* Start the decompressor */ jpeg_start_decompress(&cinfo); /* Allocate memory for the image buffer */ unsigned char *buffer = (unsigned char*)malloc(cinfo.output_width * cinfo.output_height * cinfo.output_components); /* Read the image data */ unsigned char *row_pointer; while (cinfo.output_scanline < cinfo.output_height) { row_pointer = buffer + cinfo.output_scanline * cinfo.output_width * cinfo.output_components; jpeg_read_scanlines(&cinfo, &row_pointer, 1); } /* Finish decompression and release resources */ jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); fclose(infile); ``` 最后,可以使用LIBJPEG库来编码JPEG图像。以下代码展示了如何使用LIBJPEG库来编码JPEG图像: ``` /* JPEG encoding object */ jpeg_compress_struct cinfo; /* Error handler object */ jpeg_error_mgr jerr; /* Initialize the JPEG compression object with default error handling */ cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); /* Specify the output file */ FILE *outfile = fopen("output.jpg", "wb"); if (outfile == NULL) { printf("Error opening output file"); return; } jpeg_stdio_dest(&cinfo, outfile); /* Set the image parameters */ cinfo.image_width = width; cinfo.image_height = height; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; /* Set the compression parameters */ jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, quality, TRUE); /* Start the compressor */ jpeg_start_compress(&cinfo, TRUE); /* Write the image data */ unsigned char *row_pointer; while (cinfo.next_scanline < cinfo.image_height) { row_pointer = &image[cinfo.next_scanline * width * 3]; jpeg_write_scanlines(&cinfo, &row_pointer, 1); } /* Finish compression and release resources */ jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); fclose(outfile); ``` 注意,以上代码仅供参考,具体实现可能需要根据具体的应用场景进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值