Compressing and splitting sparse files under Linux

Source: Internet
Author: User

A sparse file is a file in which most of the contents of a file are empty characters.

The 100G disk file created by the virtual machine is, but the system does not immediately partition the space of 100G, but only to identify the virtual hard disk files are sparse files, until the data storage, then allocate space, which can greatly save disk utilization.


When a sparse file is Cp/scp/split/cat, it becomes a non-sparse file file by the identified sparse file, which results in a large amount of space.

This is not the result we want, you can copy/move/split the sparse file in the following way.


Create a test with a sparse file, size 1G:

DD If=/dev/zero of=test_sparse.log Bs=1 count=1 seek=1024m


To view files:

Ls-alsh Test_sparse.log

4.0K -rw-rw-r--1 lidq lidq 1.1G June 8 15:10 Test_sparse.log


Du-sh Test_sparse.log

4.0Ktest_sparse.log


You can see that the file size is not the same.


To compress a sparse file with tar:

TAR-ZCSVF test_sparse.log.tar.gz Test_sparse.log


To split a compressed file:

Split-b 1m-d-a 4 test_sparse.log.tar.gz test_sparse.log.tar.gz-


Merge split files:

Cat test_sparse.log.tar.gz-* > test_sparse.log.tar.gz


Sparse file (Baidu Encyclopedia): http://baike.baidu.com/item/%E7%A8%80%E7%96%8F%E6%96%87%E4%BB%B6


This article is from the "Old Farmer" blog, please make sure to keep this source http://jingwu.blog.51cto.com/921628/1933473

Compressing and splitting sparse files under Linux

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.