菜鸟学Linux 第024篇笔记 压缩,tar,read,script

简介:

菜鸟学Linux 第024篇笔记  压缩,tar,read,script



压缩格式:

gz, bz2, xz, zip, z


压缩算法: 算法不同,压缩比也会不同;


command

compress: FILENAME.Z

uncompress

gzip: .gz

压缩会删除原文件

-d = gunzip

-# --fast --best

              Regulate the speed of compression using the specified

              digit  #,  where  -1  or --fast indicates the fastest

              compression  method  (less  compression)  and  -9  or

              --best indicates the slowest compression method (best

              compression).  The default compression  level  is  -6

              (that  is, biased towards high compression at expense

              of speed).

gunzip /path/name.gz

解压缩会删除原文件

zcat 可以用来查看压缩的文本文档.gz


bzip2: .bz2

压缩会删除原文件

比gzip拥有更大压缩比的压缩工具,使用近似gzip(压缩大文件的时候)

-d

-#

-k --keep

              Keep (don’t delete) input files during compression or

              decompression.

bunzip2 解压bz2文件

bzcat 查看压缩文档文档.bz2

xz (压缩比更大)有的系统没有需要安装yum install xz

压缩会删除原文件

-d

-#

-k

unxz

xzdec

xzcat


zip(压缩比不大,但可以支持压缩目录)

注意:这个压缩是不会删除原文件的!!!

zip,  zipcloak,  zipnote,  zipsplit  -  package and compress

       (archive) files

unzip 解压

e.g.

zip name.zip test/*

只归档不压缩

command

 tar ( tar - The GNU version of the tar archiving utility)

[-]c --create

[-]x --extract --get

-f, --file F

-t, --list

              list the contents of an archive

-v, --verbose

              verbosely list files processed

--xattrs (保留文件的扩展属性信息)

              this option causes tar to store each file’s  extended

              attributes  in  the archive. This option also enables

              --acls and--selinux if they haven’t been set already,

              due to the fact that the data for those are stored in

              special xattrs.

-z, --gzip, --gunzip, --ungzip

              filter the archive through gzip

-j, --bzip2

              filter  archive through bzip2, use to decompress .bz2

              files

-J --xz(用最新的xz压缩或解压缩归档文件但需要tar版本)

 e.g.

   tar -tf name.tar.gz

查看压缩归档文件包含内容

   tar -xvf foo.tar

              verbosely extract foo.tar


       tar -xzf foo.tar.gz

              extract gzipped foo.tar.gz


       tar -cjf foo.tar.bz2 bar/

              create bzipped  tar  archive  of  the  directory  bar

              called foo.tar.bz2


       tar -xjf foo.tar.bz2 -C bar/

              extract  bzipped foo.tar.bz2 after changing directory

              to bar


       tar -xzf foo.tar.gz blah.txt

              extract the file blah.txt from foo.tar.gz

  

cpio (cpio - copy files to and from archives)归档工具



read 命令

可以从用户接下来所输入的字符保存到变量里

e.g.

read A B

1 3 则会将1保存到A变量 3保存到B变量

写脚本

1.从键盘让用户输入几个文件,脚本能够将此几个文件归档压缩成一个文件,

  并且可以自定义压缩方式;

2.检查某个用户,当用户登录时显示该用户已经登录;







KEY

1. #!/bin/bash

#

read -p "Three files:" FILE1 FILE2 FILE3

read -p "Save direcotry:" DEST

read -p "Compression type:{gzip|bzip2}" STY

case $STY in

gzip)

  tar -zcf ${DEST}.tar.gz $FILE1 $FILE2 $FILE3

  ;;

bzip2)

  tar -jcf ${DEST}.tar.bz2 $FILE1 $FILE2 $FILE3

  ;;

*)

  echo "Unknown."

  exit 20

  ;;

esac


2. #!/bin/bash

#

who | grep "tom" &> /dev/null 

REC=$?

while [ $REC -ne 0 ]; do

  echo "`date`, tom not in home"

  sleep 5

  who | grep "tom" &> /dev/null 

  REC=$?

done

echo "tom is at home!!"

本文转自Winthcloud博客51CTO博客,原文链接http://blog.51cto.com/winthcloud/1870958如需转载请自行联系原作者


Winthcloud

相关文章
|
Ubuntu Linux Python
Tkinter错误笔记(一):tkinter.Button在linux下出现乱码
在Linux系统中,使用Tkinter库时可能会遇到中文显示乱码的问题,这通常是由于字体支持问题导致的,可以通过更换支持中文的字体来解决。
1060 0
Tkinter错误笔记(一):tkinter.Button在linux下出现乱码
|
12月前
|
Ubuntu Linux
"unzip"命令解析:Linux下如何处理压缩文件。
总的来说,`unzip`命令是Linux系统下一款实用而方便的ZIP格式文件处理工具。本文通过简明扼要的方式,详细介绍了在各类Linux发行版上安装 `unzip`的方法,以及如何使用 `unzip`命令进行解压、查看和测试ZIP文件。希望本文章能为用户带来实际帮助,提高日常操作的效率。
2815 12
|
12月前
|
运维 监控 中间件
Linux运维笔记 - 如何使用WGCLOUD监控交换机的流量
WGCLOUD是一款开源免费的通用主机监控工具,安装使用都非常简单,它可以监控主机、服务器的cpu、内存、磁盘、流量等数据,也可以监控数据库、中间件、网络设备
|
Ubuntu Linux PHP
利用PHP压缩音频:Linux环境下的ffmpeg简易安装指南
希望这个指南能为你的编程之旅提供帮助。只需记住,每一行代码都像音乐的音符,组合在一起,创造出美妙的旋律。祝你编程愉快!
394 6
|
Linux
Linux压缩与解压“助手”
gzip压缩解压 因为都是系统自带的我们不需要安装; ls 看一下目录当前的文件,创建一个 touch 123.txt 文件; 原文件消失,压缩解压 gzip 进行压缩,(“ gzip 123.txt ”),这样就压缩完毕了; gzip 进行解压,(“ gzip -d 123.txt.gz”),这样就解压完毕了; 原文件保留,gzip -k 123.txt、gzip -dk 123.txt.gz ;
285 9
|
Linux API 开发工具
FFmpeg开发笔记(五十九)Linux编译ijkplayer的Android平台so库
ijkplayer是由B站研发的移动端播放器,基于FFmpeg 3.4,支持Android和iOS。其源码托管于GitHub,截至2024年9月15日,获得了3.24万星标和0.81万分支,尽管已停止更新6年。本文档介绍了如何在Linux环境下编译ijkplayer的so库,以便在较新的开发环境中使用。首先需安装编译工具并调整/tmp分区大小,接着下载并安装Android SDK和NDK,最后下载ijkplayer源码并编译。详细步骤包括环境准备、工具安装及库编译等。更多FFmpeg开发知识可参考相关书籍。
806 0
FFmpeg开发笔记(五十九)Linux编译ijkplayer的Android平台so库
|
运维 Linux
Linux命令(66)之tar
Linux命令(66)之tar
355 6
|
Linux
Linux命令之tar
Linux命令之tar
354 3
|
算法 Linux
【Linux】常用的压缩解压缩命令之tar命令
【Linux】常用的压缩解压缩命令之tar命令
1203 0
|
Linux
Linux命令之解压缩:tar、zip、rar 命令
Linux命令之解压缩:tar、zip、rar 命令
334 0