首页 > 系统相关 >Linux基础 - 解压缩

Linux基础 - 解压缩

时间:2023-02-18 19:34:34浏览次数:34  
标签:zip tar 解压缩 基础 yum centos78 Linux root testdir

 

tar zcvf td2.tar.gz ./testdir/ --exclude=df.sh --exclude=a*    # 备份时,排除文件和文件目录
tar -N '2023-02-19 18:00:00' -zcvf /tmp/r.tar.gz /root/        # 只备份特定时间后的文件

tar -zcvf - yum.repos.d/ | openssl des3 -salt -k {passwd} -out /root/yum.tar.gz  # 打包时加密
openssl des3 -d -k {passwd} -salt -in yum.tar.gz | tar zxvf -                    # 加密后解包

 

### gzip
[root@centos78 tmp]# gzip yum.log         # 压缩后源文件消失
[root@centos78 tmp]# gzip -d yum.log.gz   

[root@centos78 ~]# gzip -r testdir/       # 递归对文件目录下的文件进行压缩
[root@centos78 testdir]# ls
ab  ab.txt.gz  ac  bb.log.gz  bc.log.gz  bd  be  dd.sh.gz  df  df.sh.gz  dg
[root@centos78 ~]# gzip -d -r testdir/    # 解压

### bzip2 不能对文件目录操作
[root@centos78 ~]# bzip2 -z ab.txt        # 压缩后源文件消失
[root@centos78 ~]# bzip2 -d ab.txt.bz2    # 解压文件

### zip与unzip
[root@centos78 ~]# yum install zip unzip
[root@centos78 ~]# zip ab.txt.zip ab.txt  # 源文件不会消失
[root@centos78 ~]# unzip ab.txt.zip       # zip文件不会消失
Archive:  ab.txt.zip
replace ab.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
 extracting: ab.txt

[root@centos78 ~]# zip -r td.zip  testdir/
[root@myos ~]# zip abc2.zip abc/ hsperfdata_root/     # 只打包文件目录
[root@myos ~]# zip -r abc2.zip abc/ hsperfdata_root/  # 将文件夹及其下文件进行打包
[root@myos ~]# unzip -l abc2.zip                      # 查看zip包的内容
[root@myos ~]# unzip abc2.zip -d /usr/                # 解压到指定路径

  

# -N只对特定时间之后的进行打包
[root@centos78 ~]# ll
total 8
-rw-r--r--. 1 root root    3 Feb 19 18:27 ab.txt
-rw-------. 1 root root 1259 Feb 19 17:17 anaconda-ks.cfg

[root@centos78 ~]# tar -N '2023-02-19 18:00:00' -zcvf /tmp/r.tar.gz /root/
tar: Removing leading `/' from member names
/root/
/root/.bash_history
/root/ab.txt
[root@centos78 ~]# tar tvf /tmp/r.tar.gz
dr-xr-x--- root/root         0 2023-02-19 18:26 root/
-rw------- root/root       976 2023-02-19 18:09 root/.bash_history
-rw-r--r-- root/root         3 2023-02-19 18:27 root/ab.txt

 

# 排除指定文件
[root@centos78 testdir]# ls
ab  ab.txt  ac  bb.log  bc.log  bd  be  dd.sh  df  df.sh  dg
[root@centos78 testdir]# cd ..
[root@centos78 ~]# tar zcvf td1.tar.gz ./testdir/ --exclude=df.sh
./testdir/
./testdir/ab/
./testdir/ac/
./testdir/bd/
./testdir/be/
./testdir/df/
./testdir/dg/
./testdir/ab.txt
./testdir/bb.log
./testdir/bc.log
./testdir/dd.sh
[root@centos78 ~]# tar zcvf td2.tar.gz ./testdir/ --exclude=df.sh --exclude=a*
./testdir/
./testdir/bd/
./testdir/be/
./testdir/df/
./testdir/dg/
./testdir/bb.log
./testdir/bc.log
./testdir/dd.sh

 

[root@centos78 ~]# tar -cvf /tmp/etc.tar /etc       # 仅打包,不压缩
[root@centos78 ~]# tar -xvf etc.tar                 # 解包

[root@centos78 ~]# tar -zcvf /tmp/etc.tar.gz /etc   # 打包,以gzip压缩
[root@centos78 ~]# tar -zxvf /tmp/etc.tar.gz        # 解包

[root@centos78 ~]# yum install bzip2
[root@centos78 ~]# tar -jcvf /tmp/etc.tar.bz2 /etc  # 打包,以bzip2压缩
[root@centos78 ~]# tar -jxvf /tmp/etc.tar.bz2       # 解包
 
[root@centos78 ~]# tar tvf /tmp/etc.tar             # -t 查看压缩包中文件列表, -v 查看文件的详细信息
[root@centos78 ~]# tar tvf /tmp/etc.tar.bz2
[root@centos78 ~]# tar zxvfp /tmp/etc.tar.gz        # -p 解压时保存文件原有属性

[root@centos78 ~]# tar zxvf /tmp/etc.tar.gz etc/group  # 只解压出包中的一个文件
etc/group 

[root@centos78 tmp]# tar -cvf - /etc | tar -xvf -      # 将/etc打包后直接解开到/tmp,在shell中使用

 

[root@cl-node03 docker_image_build]# ls
Dockerfile  index.html  nginx-1.20.1.tar.gz  yum.repos.d
[root@cl-node03 docker_image_build]# tar -zcvf - yum.repos.d/ | openssl des3 -salt -k {passwd} -out /root/yum.tar.gz
yum.repos.d/
yum.repos.d/CentOS-Base.repo
yum.repos.d/CentOS-CR.repo
yum.repos.d/CentOS-Debuginfo.repo
yum.repos.d/CentOS-Media.repo
yum.repos.d/CentOS-Sources.repo
yum.repos.d/CentOS-Vault.repo
yum.repos.d/CentOS-fasttrack.repo
yum.repos.d/CentOS-x86_64-kernel.repo

[root@cl-node03 ~]# tar zxvf yum.tar.gz 
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

[root@cl-node03 ~]# openssl des3 -d -k {passwd} -salt -in yum.tar.gz | tar zxvf -
yum.repos.d/
yum.repos.d/CentOS-Base.repo
yum.repos.d/CentOS-CR.repo
yum.repos.d/CentOS-Debuginfo.repo
yum.repos.d/CentOS-Media.repo
yum.repos.d/CentOS-Sources.repo
yum.repos.d/CentOS-Vault.repo
yum.repos.d/CentOS-fasttrack.repo
yum.repos.d/CentOS-x86_64-kernel.repo

 

[root@myos ~]# zip
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
Zip 3.0 (July 5th 2008). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
  The default action is to add or replace zipfile entries from list, which
  can include the special name - to compress standard input.
  If zipfile and list are omitted, zip compresses stdin to stdout.
  -f   freshen: only changed files  -u   update: only changed or new files
  -d   delete entries in zipfile    -m   move into zipfile (delete OS files)
  -r   recurse into directories     -j   junk (don't record) directory names
  -0   store only                   -l   convert LF to CR LF (-ll CR LF to LF)
  -1   compress faster              -9   compress better
  -q   quiet operation              -v   verbose operation/print version info
  -c   add one-line comments        -z   add zipfile comment
  -@   read names from stdin        -o   make zipfile as old as latest entry
  -x   exclude the following names  -i   include only the following names
  -F   fix zipfile (-FF try harder) -D   do not add directory entries
  -A   adjust self-extracting exe   -J   junk zipfile prefix (unzipsfx)
  -T   test zipfile integrity       -X   eXclude eXtra file attributes
  -y   store symbolic links as the link instead of the referenced file
  -e   encrypt                      -n   don't compress these suffixes
  -h2  show more help

[root@myos ~]#  unzip
UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment only
  -v  list verbosely/show version info       -T  timestamp archive to latest
  -x  exclude files that follow (in xlist)   -d  extract files into exdir
modifiers:
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
  -j  junk paths (do not make directories)   -aa treat ALL files as text
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives
  -I CHARSET  specify a character encoding for UNIX and other archives

See "unzip -hh" or unzip.txt for more help.  Examples:
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
  

  

 

 

标签:zip,tar,解压缩,基础,yum,centos78,Linux,root,testdir
From: https://www.cnblogs.com/kingdomer/p/9410411.html

相关文章

  • JDBC基础
    JDBC基础1.通过代码实现连接数据库publicstaticvoidconnection1(){try{Class.forName("com.mysql.cj.jdbc.Driver");Stringurl......
  • linux交换分区
    开启swap虚拟交换内存会影响性能,如果内存足够用的话,不建议开启,开启swap主要是为了解决实际内存太小,内存容量不足的情况。swap分区在系统的物理内存不够用的时候,把硬盘空......
  • vue基础:组件其他、组件间通信之父传子(通过自定义属性)、组件间通信之子传父(通过自定义
    目录一、组件其他二、组件间通信之父传子(通过自定义属性)三、组件间通信之子传父(通过自定义事件)四、ref属性五、动态组件5.0不使用动态组件5.1动态组件component标签5.2......
  • linux源码解析13- 反向映射RAMP详解
    1.什么是反向映射是一种物理地址反向映射虚拟地址的方法;正向映射:用户访问的虚拟地址,经过多级页表转化,最终映射到物理页面;反向映射:根据物理页面,找到所有映射到这个页面的......
  • Python 学习01 基础知识
    ......
  • linux数据恢复方法
    1 块设备挂载目录后分区丢失后数据恢复方法1.1问题产生操作步骤:分区:fdisk/dev/sdb;n;然后一路回车;最后w保存;可以看到sdb有了一个分区sdb1格式化:mkext3.fs/dev/sdb1......
  • 配置LINUX服务器和GEO数据处理
    1.服务器端Anaconda安装&配置1.1下载Anaconda安装包wgethttps://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh1.2安装bashAnaconda3-2022.05......
  • linux命令
    Linux的基础使用命令基本格式Linux执行命令的一般格式:命令名称[命令参数][命令对象]命令名称、命令参数、命令对象之间用空格分隔。命令参数则可以用长格式(-......
  • Linux 服务 | rsyslog
    rsyslog是实现日志功能的服务,用来采集日志信息。主配置文件/etc/rsyslog.conf中,可以设置日志的处理方式。MODULES默认开启的两个imuxsock、imjournalimuxsock......
  • Linux基础 - 用户管理
     [root@my-node10~]#useruseradduserdelusermodusers[root@my-node10~]#groupgroupaddgroupdelgroupmemsgroupmodgroups 新增用户: usera......