Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

bzip2, bunzip2, bzcat

Compress files to .bz2 (bzip2), unpack them (bunzip2), or read them without unpacking (bzcat).

Niveau
RHCSA-examen
Groep
Archiveren en comprimeren
Root nodig
Nee
Pakket
bzip2
Ook
bunzip2, bzcat, bzgrep

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

bzip2 makes smaller files than gzip, but it is slower. It replaces FILE with FILE.bz2. The RHCSA objectives name bzip2 together with tar and gzip.

Like gzip, it works on single files. For folders, use tar -cjf (the -j option calls bzip2).

Read .bz2 files without unpacking with bzcat, bzless, bzgrep.

Zo schrijf je het

bzip2 [OPTIONS] [FILE...]
bunzip2 [OPTIONS] [FILE...]
bzcat [-s] [FILE...]

Opties 14

Meest gebruikt

-d, --decompress
Decompress (same as bunzip2).
-z, --compress
Compress (the default for bzip2).
-k, --keep
Keep the original file.
-c, --stdout
Write to the screen (stdout), keep the files.
-t, --test
Test the file: is it complete and not damaged?
-f, --force
Overwrite existing output files.
-q, --quiet
Hide warnings that are not important.
-v, --verbose
Show the ratio of each file (-vv for more).
-s, --small
Use less memory (slower), for small machines.
-1 ... -9
Block size 100k to 900k. -9 (the default) compresses best.
--fast
Same as -1.
--best
Same as -9.
-L, --license, -V, --version
Show the license and version.
-h, --help
Show help.

Voorbeelden 12

$ als gewone gebruiker# als root (of met sudo)

  1. 1Compress a file

    bzip2 report.csv

    You get report.csv.bz2; the original is removed.

  2. 2Decompress

    bunzip2 report.csv.bz2

    Same as bzip2 -d report.csv.bz2.

  3. 3Keep the original

    bzip2 -k big.log

    Both files stay.

  4. 4Make a tar archive with bzip2

    tar -cjf etc.tar.bz2 /etc

    The -j option uses bzip2.

  5. 5Extract a tar.bz2 archive

    tar -xjf etc.tar.bz2 -C /tmp

    Plain -xf also works; tar detects bzip2.

  6. 6Read without unpacking

    bzcat data.txt.bz2 | head

    Fast look at the first lines.

  7. 7Search inside .bz2 files

    bzgrep "ERROR" app-*.log.bz2

    Like grep, but on compressed files.

  8. 8Test a file

    bzip2 -tv backup.sql.bz2

    Shows "ok" when the file is good.

  9. 9Compare sizes of gzip, bzip2 and xz

    for c in gzip bzip2 xz; do $c -c big.log > big.$c; done; ls -lh big.*

    See which one fits your data best.

  10. 10Compress a stream

    mysqldump shop | bzip2 > shop.sql.bz2

    No uncompressed copy on disk.

  11. 11Decompress to stdout and keep the archive

    bzip2 -dc logs.tar.bz2 | tar -t

    List the tar content without writing anything.

  12. 12Use less memory on a small VM

    bzip2 -s huge.dump

    Slower, but it fits in little RAM.

Let op

  • bzip2 removes the original by default. Use -k to keep it.
  • bzip2 is slow for big data. For speed use gzip (or pigz); for the smallest size use xz.

Tips om te onthouden

  • bzip2 / bunzip2 / bzcat. In tar: -j.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man bzip2