Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bz2 files compression question

When we compress a folder, we type the command tar -cjf folder.tar.bz2 folder, it compresses the entire folder into it.

Is there anyway to compress everything within the folder but the folder should not appear in the archive?

Example- when open the archive, the files within the folder will appear instead of the entire folder.

like image 652
op1 Avatar asked Jan 17 '11 01:01

op1


People also ask

How do you use BZ2 compression?

How to Use “bzip2” to Compress Files in Linux. Important: By default, bzip2 deletes the input files during compression or decompression, to keep the input files, use the -k or --keep option. In addition, the -f or --force flag will force bzip2 to overwrite an existing output file.

What compression rate does bzip2 achieve on the file?

bzip2 compresses data in blocks of size between 100 and 900 kB and uses the Burrows–Wheeler transform to convert frequently-recurring character sequences into strings of identical letters.

Is BZ2 lossless?

Moreover, like those programs, the compression is lossless, meaning that no data is lost during compression and thus the original files can be exactly regenerated. The only disadvantage of bzip2 is that it is somewhat slower than gzip and zip.

Can bzip2 compress directory?

Bzip2 compression To compress a directory, you can create a tar and compress it.


2 Answers

Use -C parameter of tar

tar -C folder -jcvf folder.tar.bz2 .

I tried this in my PC and it worked ;)

like image 50
Serdar Dalgic Avatar answered Sep 30 '22 01:09

Serdar Dalgic


This should do it:

cd folder; tar -cjf ../folder.tar.bz2 *

The * at the end gets expanded by the shell to the list of all files (except hidden) in the current directory. Try echo *.

For hidden files, there are two possible approaches:

  1. Use the ls command with its -A option (list "almost all" files, that is all except . and .. entries for this and parent directory.

    cd folder; tar -cjf ../folder.tar.bz2 $(ls -A)

  2. Use wildcard expressions (note that this doesn't work in dash, and, when any of the patterns doesn't match, you'll get it verbatim in the argument list)

    cd folder; tar -cjf ../folder.tar.bz2 * .[^.]* ..?*

like image 41
jpalecek Avatar answered Sep 30 '22 01:09

jpalecek