LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tar command help (https://www.linuxquestions.org/questions/linux-newbie-8/tar-command-help-755801/)

caponewgp 09-17-2009 12:46 AM

tar command help
 
I had a question about using the tar command. Ive been working on trying to compress some files.
So lets say I have 4 files
backup1.txt
backup2.txt
backup3.txt
backup4.txt
And these are the only files in the directory I can run
tar cvf * to combine the files and create a single compressed file However since im not specifying a file name how would the tar command name the compressed file. Would it just be backup.txt.tar or just backup.tar? Im just not sure how the naming would work.

themanwhowas 09-17-2009 01:09 AM

it would create an archive called backup1.txt which would contain 3 files (backup2.txt, backup3.txt and backup4.txt)

lutusp 09-17-2009 01:12 AM

Quote:

Originally Posted by caponewgp (Post 3686432)
I had a question about using the tar command. Ive been working on trying to compress some files.
So lets say I have 4 files
backup1.txt
backup2.txt
backup3.txt
backup4.txt
And these are the only files in the directory I can run
tar cvf * to combine the files and create a single compressed file

Yes, but this is a mistake -- the archive is given the name of the first file in the list (and that file's contents are lost). You don't want to do this.

Also, use the standard syntax -- prefix a "-" to the option list:

Code:

$ tar -cvf archive_name.tar *
Quote:

Originally Posted by caponewgp (Post 3686432)
However since im not specifying a file name how would the tar command name the compressed file. Would it just be backup.txt.tar or just backup.tar? Im just not sure how the naming would work.

So you aren't giving TAR a filename and you wonder what TAR will do without any guidance? Have you considered solving the problem by giving TAR a filename? Have you considered performing an experiment to test your assumptions?

You must give TAR either a filename or "-" as a signal to dump the archive onto the output stream:

Code:

$ tar -cvf - * # to output stream
Code:

$ tar -cvf archive.tar * # to a file named "archive.tar"
A warning. If you don't do either of these things, TAR will erase the first file in the list and replace its contents with its archive of the remaining listed files. Please read:

Code:

$ man tar

vinaytp 09-17-2009 01:12 AM

Quote:

Originally Posted by caponewgp (Post 3686432)
I had a question about using the tar command. Ive been working on trying to compress some files.
So lets say I have 4 files
backup1.txt
backup2.txt
backup3.txt
backup4.txt
And these are the only files in the directory I can run
tar cvf * to combine the files and create a single compressed file However since im not specifying a file name how would the tar command name the compressed file. Would it just be backup.txt.tar or just backup.tar? Im just not sure how the naming would work.

You Have to give the name explicitly i guess

tar -cvf backup *

Here backup will become the compressed file
Also I recommend using cpio rather than tar you can also use

find . | cpio -ocv > backup

you can extract backup using

cpio -i < backup

Hope this will be helpfull

lutusp 09-17-2009 01:20 AM

Quote:

Originally Posted by vinaytp (Post 3686448)
You Have to give the name explicitly i guess

tar -cvf backup *

Here backup will become the compressed file

Yes, except that it isn't compressed. For compression, you need to:

Code:

$ tar -czvf backup.tar.gz * # gzip compression
Code:

$ tar -cjvf backup.tar.bz2 * # BZ2 compression
The second compresses more, but takes longer to run.

caponewgp 09-17-2009 01:24 AM

Thanks everyone for your help hopefully once I have a few months getting used to this system Ill be able to help other people out as well.


All times are GMT -5. The time now is 10:16 AM.