Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 09-07-2002, 06:35 PM   #1
Registered: Aug 2002
Location: Huntsville AL
Distribution: redhat 7.3
Posts: 48

Rep: Reputation: 15
tar a directory

If I use the following command : tar czvf somedirectory.tar directory ......... will this tar up my entire directory path to include hidden files?

Would I then use the : tar xzvf somedirectory.tar to untar a mirror image of the entire directory tree plus hidden files to the location of my choice?

I've read the man pages, tried it and seams to work....just want some input to make sure I'm doing this right.

Thanks ahead. ......doesn't hurt to ask .
Old 09-07-2002, 06:53 PM   #2
Registered: Apr 2002
Distribution: redhat7, 7.1, 7.2, 8.0, mandrake, debian2.2, 3, suse
Posts: 176

Rep: Reputation: 30
tar -czvf backup.tgz /home/wambo

to undo

tar -xzvf backup.tgz
Old 09-07-2002, 08:59 PM   #3
Registered: Aug 2002
Location: Huntsville AL
Distribution: redhat 7.3
Posts: 48

Original Poster
Rep: Reputation: 15
tar,tar.gz,tgz hummmm...

Thanks for the responce. I think I understand that a tar is as in "gathered" and that *.tar.gz is added compresion if I've got it right

I hadn't seen the * that similiar to *.tar.gz ?
Old 09-07-2002, 10:45 PM   #4
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
Yes, you got it right. Tar puts all files from a directory, including its sub-directories, ownership and access-rights, in a single . tar file. The 'z'-option compresses the .tar file using gzip, thus creating a .tar.gz.

tar czvf some_name.tar.gz some_dir

is the same as:

tar cvf some_file.tar some_dir

...and then compressig it with:

gzip some_file.tar

The same goes for un-tarring (and decompressing), in the opposite order, like:

gunzip some_file.tar.gz
tar xvf some_file.tar


tar xzvf some_file.tar.gz

The 'v' options tells 'tar' to be verbose, i.e. leaving the 'v' option out will do exacly the same thing, but silently.

And, yes, "aFile.tgz" is the same as "aFile.tar.gz".

Today often tar-files are compressed with "bzip2". The files are named like "aFile.tar.bz2". You can decompress them with "bunzip2", or in one go (with recent tar versions) with the 'j' or 'I' (capital 'i') option (depends on your tar-version) instead of 'z'. Like

tar cjvf some_name.tar.bz2 some_dir


tar cIvf some_name.tar.bz2 some_dir

Last edited by Hko; 09-07-2002 at 10:49 PM.
Old 09-07-2002, 10:54 PM   #5
LQ Addict
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
To preserve permissions and ownership of the files use p flag as well
tar cvfpz archive.tar.gz [archive.tgz] /home/username
tar xvfzp archive.tar.gz [archive.tgz]
Old 09-08-2002, 09:43 AM   #6
Registered: Aug 2002
Location: Huntsville AL
Distribution: redhat 7.3
Posts: 48

Original Poster
Rep: Reputation: 15
Got it!

Now I got it !

Yeah, that works great plus the ownership and permissions.

Thanks guys !


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How Can I tar This Directory? Xian Linux - General 4 06-17-2005 07:32 PM
tar help - how to tar to a different directory thick_guy_9 Linux - Software 2 03-10-2005 05:35 PM
tar with directory path scatterbrain Linux - General 2 03-16-2004 12:05 AM
tar a directory kbeaver Linux - General 4 09-12-2003 12:00 PM
Can I tar a directory structure.... shelby Linux - General 9 02-20-2003 10:17 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:25 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration