Linux file compression and packaging __linux

Source: Internet
Author: User
Tags bz2 ldap rsyslog
Prepare for Work
[Root@centos-01 ~]# cd/tmp/[root@centos-01 tmp]# ls 1.txt
Systemd-private-40c0e692674844949b91361dc6ab4a40-chronyd.service-6km7k9
Systemd-private-40c0e692674844949b91361dc6ab4a40-vgauthd.service-3w1kyg Systemd-private-40c0e692674844949b91361dc6ab4a40-vmtoolsd.service-wjzpyd [root@centos-01 tmp]# mkdir mytest [ root@centos-01 tmp]# CD mytest/[root@centos-01 mytest]# ls [root@centos-01 mytest]# find/etc/-type f-name "*conf"/etc /lvm/lvm.conf/etc/lvm/lvmlocal.conf/etc/resolv.conf/etc/pki/ca-trust/ca-legacy.conf/etc/yum/pluginconf.d/ fastestmirror.conf/etc/yum/pluginconf.d/langpacks.conf/etc/yum/protected.d/systemd.conf/etc/yum/ version-groups.conf/etc/asound.conf/etc/sasl2/smtpd.conf/etc/logrotate.conf/etc/openldap/ldap.conf/etc/ libuser.conf/etc/sestatus.conf/etc/yum.conf/etc/host.conf/etc/dracut.conf/etc/dbus-1/system.d/teamd.conf/etc/ dbus-1/system.d/org.freedesktop.hostname1.conf/etc/dbus-1/system.d/org.freedesktop.import1.conf/etc/dbus-1/ System.d/org.freedesktop.Locale1.conf/etc/dbus-1/system.d/org.freedesktop.login1.conf/etc/dbus-1/system.d/org.freedesktop.machine1.conf /etc/dbus-1/system.d/org.freedesktop.systemd1.conf/etc/dbus-1/system.d/org.freedesktop.timedate1.conf/etc/ dbus-1/system.d/org.freedesktop.policykit1.conf/etc/dbus-1/system.d/wpa_supplicant.conf/etc/dbus-1/system.d/ nm-dispatcher.conf/etc/dbus-1/system.d/nm-ifcfg-rh.conf/etc/dbus-1/system.d/ org.freedesktop.networkmanager.conf/etc/dbus-1/system.d/com.redhat.tuned.conf/etc/dbus-1/system.d/ firewalld.conf/etc/dbus-1/system.d/dnsmasq.conf/etc/dbus-1/session.conf/etc/dbus-1/system.conf/etc/depmod.d/ dist.conf/etc/modprobe.d/tuned.conf/etc/systemd/bootchart.conf/etc/systemd/coredump.conf/etc/systemd/ journald.conf/etc/systemd/logind.conf/etc/systemd/system.conf/etc/systemd/user.conf/etc/rsyslog.d/listen.conf/ etc/x11/xorg.conf.d/00-keyboard.conf/etc/prelink.conf.d/nss-softokn-prelink.conf/etc/prelink.conf.d/ Fipscheck.conf/etc/prelink.conf.d/grub2.conf/etc/ld.so.Conf/etc/ld.so.conf.d/mariadb-x86_64.conf/etc/ld.so.conf.d/kernel-3.10.0-693.el7.x86_64.conf/etc/nsswitch.conf /etc/udev/udev.conf/etc/networkmanager/networkmanager.conf/etc/libaudit.conf/etc/fuse.conf/etc/geoip.conf/etc/ selinux/semanage.conf/etc/selinux/targeted/setrans.conf/etc/sysctl.conf/etc/krb5.conf/etc/security/ pwquality.conf/etc/security/access.conf/etc/security/chroot.conf/etc/security/group.conf/etc/security/ limits.conf/etc/security/limits.d/20-nproc.conf/etc/security/namespace.conf/etc/security/pam_env.conf/etc/ security/sepermit.conf/etc/security/time.conf/etc/wpa_supplicant/wpa_supplicant.conf/etc/plymouth/ Plymouthd.conf/etc/tuned/tuned-main.conf/etc/vmware-tools/guestproxy-ssl.conf/etc/vmware-tools/vgauth.conf/etc /firewalld/firewalld.conf/etc/kdump.conf/etc/audisp/audispd.conf/etc/audisp/plugins.d/af_unix.conf/etc/audisp/ plugins.d/syslog.conf/etc/audit/auditd.conf/etc/chrony.conf/etc/rsyslog.conf/etc/man_db.conf/etc/ sudo-ldap.conf/etc/sudo.conf/etc/e2fsck.conf/etc/mke2fs.conf/etc/vconsole.conf/etc/locale.conf/etc/updatedb.conf/etc/dnsmasq.conf [
root@centos-01 mytest]# find/etc/-type f-name "*conf"-exec Cat {} >> 2.txt \;  [root@centos-01 mytest]# ls 2.txt [root@centos-01 mytest]# du-sh 2.txt 240K 2.txt [root@centos-01 mytest]# find/etc/
-type f-name "*conf"-exec Cat {} >> 2.txt \; [root@centos-01 mytest]# du-sh 2.txt 476K 2.txt [root@centos-01 mytest]# find/etc/-type f-name "*conf"-exec Cat {
} >> 2.txt \; [root@centos-01 mytest]# du-sh 2.txt 1.2M 2.txt [root@centos-01 mytest]# find/etc/-type f-name "*conf"-exec Cat {
} >> 2.txt \; [root@centos-01 mytest]# du-sh 2.txt 1.2M 2.txt [root@centos-01 mytest]# find/etc/-type f-name "*conf"-exec Cat {
} >> 2.txt \; [root@centos-01 mytest]# du-sh 2.txt 1.2M 2.txt [root@centos-01 mytest]# find/etc/-type f-name "*conf"-exec Cat {
} >> 2.txt \; [root@centos-01 mytest]# du-sh 2.txt 2.2M 2.txt [root@centos-01 mytest]# wc-l 2.txt 36486 2.txt
 
gzip Compression Tool

Syntax: gzip [-DN] filename (n is a number of 1-9) "-D": Decompression using the "-N" (n is 1-9 of the number): compression level, the 1th level is the fastest compression, but the smallest compression, the 9th level of compression is the slowest, but the maximum amount of compression. The default level is 6, and "--fast" and "--best" are equivalent to "1" and "9" respectively.

[root@centos-01 mytest]# gzip 2.txt 
[root@centos-01 mytest]# ls
2.txt.gz
[root@centos-01 mytest]# du-sh 2. txt.gz 
376K    2.txt.gz
[root@centos-01 mytest]# gzip-d 2.txt.gz 
[root@centos-01 mytest]# ls
2.txt
[root@centos-01 mytest]# du-sh 2.txt 
1.4M    2.txt
[root@centos-01 mytest]# wc-l 2.txt 
36486 2. TXT
[root@centos-01 mytest]# gzip-1 2.txt 
[root@centos-01 mytest]# du-sh 2.txt.gz 
444K    2.txt.gz< c17/>[root@centos-01 mytest]# gunzip 2.txt.gz 
[root@centos-01 mytest]# ls
2.txt
[root@centos-01 mytest]# gzip-9 2.txt 
[root@centos-01 mytest]# du-sh 2.txt.gz 
372K    2.txt.gz
[root@centos-01 mytest]# ls
2.txt.gz
[root@centos-01 mytest]# file 2.txt.gz 2.txt.gz:gzip compressed 
data, was "2.txt", From Unix, last Modified:fri may  4 10:49:46 2018, max compression
Zcat command to view compressed file contents
[Root@centos-01 mytest]# Zcat 2.txt.gz
[root@centos-01 mytest]# ls
2.txt.gz
[root@centos-01 mytest]# gzip-d 2.txt.gz 
[root@centos-01 mytest]# Gzip-c 2.txt >/tmp/2.txt.gz
[root@centos-01 mytest]# ls
2.txt
[root@centos-01 mytest]# ls/tmp/
1. TXT     systemd-private-ad61a62cb5b4492ca6ac55582093dd32-chronyd.service-yzd92d
2.txt.gz  SYSTEMD-PRIVATE-AD61A62CB5B4492CA6AC55582093DD32-VGAUTHD.SERVICE-INJEWP
mytest    Systemd-private-ad61a62cb5b4492ca6ac55582093dd32-vmtoolsd.service-exaldt
[root@centos-01 mytest]# file/tmp/ 2.txt.gz 
/tmp/2.txt.gz:gzip Compressed data, is "2.txt", from Unix, last Modified:fri may  4 10:49:46 2018
  [root@centos-01 mytest]# gzip-d-c/tmp/2.txt.gz >/tmp/mytest/3.txt
[root@centos-01 mytest]# ls
2.txt< C18/>3.txt
[root@centos-01 mytest]# wc-l 2.txt 3.txt 
  36486 2.txt
  36486 3.txt
  72972 total dosage
[ root@centos-01 mytest]# du-sh *.txt
1.4M    2.txt
1.4M    3.txt
Gzip is not supported for compressed directories. bzip2 Compression Tool
[root@centos-01 mytest]# bzip2 2.txt 
-bash:bzip2: Command not found
[root@centos-01 mytest]# yum Install-y] bzip2

Syntax: bzip2 [-dz] filename "-D": Decompression "-Z": Compression

[root@centos-01 mytest]# bzip2 2.txt 
[root@centos-01 mytest]# ls
2.txt.bz2  3.txt
[root@centos-01 mytest]# du-sh 2.txt.bz2 
160K    2.txt.bz2
[root@centos-01 mytest]# bzip2-d 2.txt.bz2 
[root@centos-01 mytest]# ls
2.txt  3.txt
[root@centos-01 mytest]# bzip2 2.txt 
[root@centos-01 mytest]# bunzip2 2. txt.bz2 
[root@centos-01 mytest]# ls
2.txt  3.txt
[root@centos-01 mytest]# ls/tmp/
1.txt     Systemd-private-604486059e93474a8b695802ff294d42-chronyd.service-nvd2qs
2.txt.gz  systemd-private-604486059e93474a8b695802ff294d42-vgauthd.service-xkkbjw
mytest    Systemd-private-604486059e93474a8b695802ff294d42-vmtoolsd.service-yajkga
[root@centos-01 mytest]# bzip2-c 2. TXT >/tmp/3.txt.bz2
[root@centos-01 mytest]# du-sh/tmp/3.txt.bz2 
160K    /tmp/3.txt.bz2
[ root@centos-01 mytest]# bzip2-d-c/tmp/3.txt.bz2 > 4.txt
[root@centos-01 mytest]# ls
2.txt  3.txt< C30/>4.txt
[root@centos-01 mytest]# du-sh 4.txt 
1.4M    4.txt
Bzcat command to view compressed file contents
[Root@centos-01 mytest]# bzcat/tmp/3.txt.bz2
BZIP2 cannot compress a directory XZ Compression Tool
[root@centos-01 mytest]# xz 2.txt [root@centos-01 mytest]# ls 2.txt.xz 3.txt 4.txt [root@centos-01 mytest]# du-sh 2.tx T.xz 56K 2.txt.xz [root@centos-01 mytest]# xz-d 2.txt.xz [root@centos-01 mytest]# ls 2.txt 3.txt 4.txt [root@centos-0 1 mytest]# xz 2.txt [root@centos-01 mytest]# unxz 2.txt.xz [root@centos-01 mytest]# ls 2.txt 3.txt 4.txt [root@centos- mytest]# ls/tmp/1.txt Systemd-private-604486059e93474a8b695802ff294d42-chronyd.service-nvd2qs 2.txt.gz systemd  -PRIVATE-604486059E93474A8B695802FF294D42-VGAUTHD.SERVICE-XKKBJW 3.txt.bz2 Systemd-private-604486059e93474a8b695802ff294d42-vmtoolsd.service-yajkga mytest [root@centos-01 mytest]# xz-c 2.txt >/tmp/4.txt.xz [root@centos-01 mytest]# xz-d-c/tmp/4.txt.xz >/1.txt [root@centos-01 mytest]# ll Total dosage 5712-rw-r --r--. 1 root 1460358 May 4 20:42 1.txt-rw-r--r--. 1 root 1460358 May 4 10:49 2.txt-rw-r--r--. 1 root 1460358 May 4 20:28 3.txt-rw-r--r--. 1 root 1460358 May 4 20:30 4.txT 
Xzcat command to view compressed file contents
[Root@centos-01 mytest]# Xzcat/tmp/4.txt.xz
Zip compression tool
[root@centos-01 mytest]# tree/tmp/
/tmp/
├──1.txt
├──2.txt.gz ├──3.txt.bz2 ├──4.txt.xz ├──mytest
│   ├──1.txt
│   ├──2.txt
│   ├──3.txt
│   ├──4.txt
│   └── Yourtest
│       ├──1.txt
│       ├──2.txt
│       ├──3.txt
│       └──4.txt
├── Systemd-private-604486059e93474a8b695802ff294d42-chronyd.service-nvd2qs
│   └──tmp
├── SYSTEMD-PRIVATE-604486059E93474A8B695802FF294D42-VGAUTHD.SERVICE-XKKBJW
│   └──tmp
└── Systemd-private-604486059e93474a8b695802ff294d42-vmtoolsd.service-yajkga
    └──tmp
        └──vmware-root

9 directories, files
[root@centos-01 mytest]# du-sh yourtest/
5.6M    yourtest/
[root@centos-01 mytest]# zip 2.txt.zip 2.txt
-bash:zip: Command not found
[root@centos-01 mytest]# yum install-y zip
[root@centos-01 mytest]# zip 2.txt.zip 2.txt adding:2.txt (deflated 74%) [root@centos-01 mytest]# du-sh 2.txt.zip 376K 2.txt.zip [root@centos-01 mytest]# ls 1.txt 2.txt 2.txt.zip 3.txt 4 . txt yourtest [root@centos-01 mytest]# zip-r yourtest.zip yourtest 3.txt adding:yourtest/(stored 0) adding:your Test/3.txt (deflated 74%) Adding:yourtest/4.txt (deflated 74%) Adding:yourtest/2.txt (deflated 74%) Adding:yourte
St/1.txt (deflated 74%) Adding:3.txt (deflated 74%) [root@centos-01 mytest]# ls 1.txt 2.txt 2.txt.zip 3.txt 4.txt yourtest yourtest.zip [root@centos-01 mytest]# Du-sh Yourtest.zip 1.9M yourtest.zip [root@centos-01 mytest]# unzip-bash:unzip: Command not found [root@centos-< 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.