Compressing directory with bzip2
I'm trying to compress a directory with bzip2. According to documentation I have to 'bzip2 whatever.bz2 dirtopack'. But it gives me a big:
Code:
bzip2: Can't open input file whatever.bz2: No such file or directory. |
You seem to misunderstand the difference between tar and bzip2.
tar is a file archive utility that takes a number of files, with pathnames, and puts them into a single binary file. It doesn't do anything to compress the data. bzip2 (like gzip and compress) is a file (or stream) compression utility, that takes a single file and makes it smaller. If you want to create an archive of a directory, you first need to create a tar archive, then bzip2 compress the archive; this is why “tarball”s often have the extension .tar.bz2 Code:
tar -cf file.tar dir && bzip2 file.tar Code:
tar -cjf file.tar.bz2 dir If you want to compress each file within a directory, you can use Code:
bzip2 dir/* Code:
find dir -exec bzip2 '{}' ';' |
Best way to compress as 2016
I was googling how to do the best compression of a directory on linux and I found that if you have memory XZ is the best as they explain it here how to compress a directory in linux
|
I always just use the 'j' switch with 'tar'.
|
It all depends on what you're trying to do, really.
gzip (-z with tar) is generally fastest to compress and uncompress, but only provides limited compression. bzip (-j with tar) provides slightly better compression than gzip (except for very small files - unlikely with tar) and takes a little more cpu and memory, but is generally a good alternative. xz (-J with tar) provides the best compression ratio, but is expensive in terms of time and memory used, so generally best for archiving or creating big distributions over slower networks. |
All times are GMT -5. The time now is 06:34 PM. |