LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tar error (https://www.linuxquestions.org/questions/linux-newbie-8/tar-error-796641/)

salimshahzad 03-20-2010 04:22 AM

tar error
 
dear gurus i am facing tar error i try many ways but always fail i copy some file/folder from windows pc to linux and wish to make .tar.gz file

however other location folders it is working fine

[root@test7 ]# tar -cvf /test/backup_app/test_app.tar.gz
tar: Cowardly refusing to create an empty archive
Try `tar --help' or `tar --usage' for more information

[root@test7 ]# tar cvzf /test/backup_app/test_app.tar.gz
tar: Cowardly refusing to create an empty archive
Try `tar --help' or `tar --usage' for more information

[root@test7 ]# tar -cvzf /test/backup_app/test_app.tar.gz
tar: Cowardly refusing to create an empty archive
Try `tar --help' or `tar --usage' for more information

regards

Maligree 03-20-2010 04:29 AM

You didn't tell tar what to archive:
Code:

tar cvzf /test/backup_app/test_app.tar.gz /directory/to/tar
if you're in there already, just do
Code:

tar cvzf /test/backup_app/test_app.tar.gz .

druuna 03-20-2010 05:32 AM

Hi,

@salimshahzad: The command given is not correct. You need to tell tar the name of the archive (which you did) and what to tar (which you did not).

tar cvf name.of.archive.tar /target/to/tar
or
tar cvf name.of.archive.tar file1 file2

Take a look here: tar manual: 2.6 How to Create Archives

Hope this helps.

salimshahzad 03-20-2010 05:43 AM

dear gurus thanks for support i miss next line

suggest how to do full compress or max compress in linux

rgds

druuna 03-20-2010 05:49 AM

Hi,

Tar (the basics) just creates an archive, it does not compress anything.

Depending on your version of tar you can go 2 ways to compress your data:

1) first use a compressing tool (like bzip2, zip, etc), then tar all the comressed files.
2) use tar's build in compression options (this needs to be present in your tar version. it probably is).

An example of the second option:

tar cvz name.tar file <- uses gzip to compress.
tar cvj name.tar file <- uses bzip2 to compress.
tar cvZ name.tar file <- uses compress to compress.

Take a look here as well: 8.1 Using Less Space through Compression

Hope this helps.

salimshahzad 03-20-2010 05:54 AM

dear gurus thanks so nice quick repsonse

some people do .tar.gz file does it means it is compress by default, as i heard there r 7-9 level of compression to use in tar/gz combination

your option tar cvZ name.tar file <- uses compress to compress.
does it compress fully max.

1 more query 2 clarify, how to do full or max compression level use in linux for any directory or files.

kind regards again
salim

druuna 03-20-2010 06:19 AM

Hi,

The name a tarfile gets is all up to the user and doesn't necessarily say anything about the way the archive was created/compressed.

Logic says (but keep my previous comment in mind) that a file ending with:

.tar -> archived with tar (no compression)
.tar.gz or .tgz -> compressed by gzip and archived by tar (the compression part can be done by tar's -z option or gzip itslef).
.tar.bz -> compressed with bzip2, archived by tar.

I don't think tar can handle the extra compression that some of the tools (gzip. bzip2 etc) have. I haven't seen options for it.
If extra compression is needed take a look at, for example, gzip's options to do so (gzip -# <1-9> <file> or gzip -best <file>). This also means that you need to gzip the file(s) first and then use tar to archive the lot.

bzip2 also has an option for extra compression: bzip2 -1 <file> -> bzip2 -9 <file> 1 being fast and less compression, 9 being slow and best compression.

Hope this helps.

nonamenobody 03-20-2010 10:32 AM

Quote:

Originally Posted by druuna (Post 3905427)
Hi,

The name a tarfile gets is all up to the user and doesn't necessarily say anything about the way the archive was created/compressed.

Logic says (but keep my previous comment in mind) that a file ending with:

.tar -> archived with tar (no compression)
.tar.gz or .tgz -> compressed by gzip and archived by tar (the compression part can be done by tar's -z option or gzip itslef).
.tar.bz -> compressed with bzip2, archived by tar.

I don't think tar can handle the extra compression that some of the tools (gzip. bzip2 etc) have. I haven't seen options for it.
If extra compression is needed take a look at, for example, gzip's options to do so (gzip -# <1-9> <file> or gzip -best <file>). This also means that you need to gzip the file(s) first and then use tar to archive the lot.

bzip2 also has an option for extra compression: bzip2 -1 <file> -> bzip -9 <file> 1 being fast and less compression, 9 being slow and best compression.

Hope this helps.

I would mostly agree with that except that:
  • If you wanted to use the 'bzip2' or 'gzip' commands to compress manually, you would archive them first using tar and then compress that one file - rather than compress each file and then archiving.
  • AFAIK The bzip2 command is 'bzip2' not 'bzip' (probably a typo).
  • I would presume that tar uses the default compression that bzip2 and gzip, but if it doesn't I doubt there are would be a lot of difference between level 1 and level 9 (certainly for bzip2, the man page indicates that there isn't much difference. I suppose you could experiment quite easily and see which level created a file the same size.
  • Typically bzip2 typically offers the best compression rates and is the slowest. Compress is (I believe) fast but doesn't offer good very ratios except for very repeatative files which it can compress better than bzip2. gzip is a good all rounder.
  • Tar can also compress using lzip, XV, LZMA and LSOP (though I have never used these, or seen them being used).
  • RAR probably offers the best compression ratios, however it included by distributors (though unrar is), so you'll have to download it from rarsoft.com
  • Files which are already compressed (e.g. JPEGs), generally can't be compressed any further. You would probably find that if you were to tar them and then gzip them, the tar.gz would be slightly larger than the original tar file.

druuna 03-20-2010 11:41 AM

Hi,

Quote:

Originally Posted by nonamenobody (Post 3905575)
I would mostly agree with that except that:[list][*]If you wanted to use the 'bzip2' or 'gzip' commands to compress manually, you would archive them first using tar and then compress that one file - rather than compress each file and then archiving.

That would depend on what is best for the situation. You are correct if the smallest possible archive is what you want/need. If disk space is a possible issue (especially during restoring), it is better to compress each individual file first and archive that. Due to the extra compress headers the archive will be a bit bigger.

Quote:

[*]AFAIK The bzip2 command is 'bzip2' not 'bzip' (probably a typo).
A typo indeed. Corrected it in my original reply. Thanks for pointing that out.

nonamenobody 03-20-2010 12:09 PM

Quote:

Originally Posted by druuna (Post 3905627)
Hi,
That would depend on what is best for the situation. You are correct if the smallest possible archive is what you want/need. If disk space is a possible issue (especially during restoring), it is better to compress each individual file first and archive that. Due to the extra compress headers the archive will be a bit bigger.

I have never even thought about doing it that way around. I'll have to remember that as there are times when it could be handy.


All times are GMT -5. The time now is 04:36 AM.