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 07-11-2006, 04:50 PM   #1
LQ Newbie
Registered: Mar 2006
Posts: 24

Rep: Reputation: 15
compress a directory using tar

Hello everyone.

What command do I give to compress an entire directory and it's sub folders to a tar file?

I want to log in via ssh, go to inside the directory I want to tar, then issue this command.

What exact command do I need to do? Do I need to tar the files first on the old sever?

I have searched these forms, and found nothing that would help answer this question. I apologize if this is an easy answer. I am unsure of what to do at the moment and appreciate any help.
Old 07-11-2006, 05:31 PM   #2
Senior Member
Registered: May 2005
Location: Paraguay
Posts: 1,565
Blog Entries: 1

Rep: Reputation: 50
man tar
Old 07-11-2006, 05:49 PM   #3
Senior Member
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,072

Rep: Reputation: 323Reputation: 323Reputation: 323Reputation: 323
(1) cd to the directory you want to tar
(2) choose your output files and directory ... I used /tmp for this example

No compression (larger output file):
$ tar cvf /tmp/outputfile.tar .
Gzip compression (smaller output file):
$ tar zcvf /tmp/outputfile.tar.gz .
Bzip compression (still smaller output file usually, but slower typically):
$ tar jcvf /tmp/outputfile.tar.bz2 .
Extract the archives created above by replacing the "c" option with "x" (c = create, x = extract). Leave off the trailing "." from the create command. Files will be extracted to your current directory.
Old 07-11-2006, 05:59 PM   #4
Registered: Oct 2005
Location: Pune, India
Distribution: OpenSUSE 11.0
Posts: 422

Rep: Reputation: 30
To compress any folder / file
tar zcvf newtarfile.tar /path/to/folder
To extract this fife back in current directory
tar zxvf newtarfile.tar
To extract this fife back to a specific directory
tar zxvf newtarfile.tar -C /path/to/extract
Old 07-18-2006, 11:24 AM   #5
LQ Newbie
Registered: Mar 2006
Posts: 24

Original Poster
Rep: Reputation: 15
For those who provided examples, thank you very much. Examples are easier to follow than the manual. I learn faster by example as I believe everyone does.

Thank you.


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
tar tar cvf - . | (cd /root/; tar xvf -) ewt3y Linux - General 10 02-19-2014 11:55 AM
a tough question 4 u, problem in extracting tar & tar.gz files p_garg Linux - General 5 11-08-2010 12:02 PM
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 10 02-23-2008 06:40 AM
.rpms, .tar.gz, .tgz, .src.rpm, & .tar.bz2 whoots Mandriva 10 10-18-2003 01:08 PM
Diferance between rpm, tar, tar.gz, scr.tar, etc mobassir Linux - General 12 08-21-2003 07:30 AM

All times are GMT -5. The time now is 07:10 PM.

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