Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-22-2005, 05:02 PM   #1
Registered: Sep 2003
Location: Gorredijk, Netherlands
Distribution: Arch Linux
Posts: 400

Rep: Reputation: 30
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:

bzip2: Can't open input file whatever.bz2: No such file or directory.
bzip2: Input file dirtopack is a directory.
What the hell am I doing wrong? I've tried some switches but nothing works. Tar works fine but bzip2 is more powerful.
Old 06-22-2005, 05:13 PM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
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
tar -cf file.tar dir && bzip2 file.tar
You can also do this in one step:
tar -cjf file.tar.bz2 dir
This compresses better than all-in-one formats like ZIP, which compress each file seperately then append then put the compressed files into an archive.

If you want to compress each file within a directory, you can use
bzip2 dir/*
To do this recursively you'll need to use find:
find dir -exec bzip2 '{}' ';'
1 members found this post helpful.
Old 12-18-2016, 04:44 PM   #3
LQ Newbie
Registered: Dec 2016
Posts: 2

Rep: Reputation: Disabled
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
Old 12-19-2016, 12:23 AM   #4
LQ Guru
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
I always just use the 'j' switch with 'tar'.
Old 12-19-2016, 03:51 PM   #5
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
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.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with compressing a directory for backup Lleb_KCir Linux - Newbie 8 10-28-2005 02:52 AM
strange problem while compressing a directory kartheekpn Linux - General 5 08-04-2005 12:39 PM
Compressing/Zipping A Directory Wha?Where? Linux - Newbie 4 07-07-2005 09:20 PM
bzip2 andzerger Linux - Software 2 02-21-2004 04:23 AM
Bzip2 ? ironz Linux - Newbie 1 06-30-2003 11:44 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:42 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration