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.
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.
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.
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.
Bzip2 compression To compress a directory, you can create a tar and compress it.
Use -C parameter of tar
tar -C folder -jcvf folder.tar.bz2 .
I tried this in my PC and it worked ;)
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:
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)
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 * .[^.]* ..?*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With