LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 06-22-2005, 06:02 PM   #1
Haiyadragon
Member
 
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:

Code:
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, 06:13 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

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
Code:
tar -cf file.tar dir && bzip2 file.tar
You can also do this in one step:
Code:
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
Code:
bzip2 dir/*
To do this recursively you'll need to use find:
Code:
find dir -exec bzip2 '{}' ';'
 
1 members found this post helpful.
Old 12-18-2016, 05:44 PM   #3
sluphiphif
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, 01:23 AM   #4
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 3,283

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

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.
  


Reply


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 03:52 AM
strange problem while compressing a directory kartheekpn Linux - General 5 08-04-2005 01:39 PM
Compressing/Zipping A Directory Wha?Where? Linux - Newbie 4 07-07-2005 10:20 PM
bzip2 andzerger Linux - Software 2 02-21-2004 05:23 AM
Bzip2 ? ironz Linux - Newbie 1 07-01-2003 12:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:05 PM.

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