LinuxQuestions.org
Register a domain and help support LQ
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 11-01-2009, 05:26 PM   #1
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Rep: Reputation: 16
Question How can i .gz all files in a directory?


Hello

I was using ssh and go inside the public_html folder of my server that all files from my website are located.

What command i must use to compress all the files and folders from that directory to .gz?

Thank you
 
Old 11-01-2009, 05:29 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,330

Rep: Reputation: 227Reputation: 227Reputation: 227
what about gzip *.* ?
 
Old 11-01-2009, 05:30 PM   #3
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
try
Code:
tar -czvf directory.tar.gz directory/
 
Old 11-01-2009, 05:31 PM   #4
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware, Mint
Posts: 1,252

Rep: Reputation: 205Reputation: 205Reputation: 205
or simply gzip * ?
 
Old 11-01-2009, 05:32 PM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,330

Rep: Reputation: 227Reputation: 227Reputation: 227
we do not know if the orignal poster wants each one gziped indiviually or all in one.
 
Old 11-01-2009, 05:36 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Do you want to compress all of the files individually, or create a tarball. Where do you want the compressed files (or tarball) located?

If you want to download a tarball of all of the files in this directory on your remote computer, you could use tar through a pipe:
ssh user@host -C <base_dir> -czf - . | cat >tarballname.tar.gz
 
Old 11-02-2009, 03:28 AM   #7
dasy2k1
Member
 
Registered: Oct 2005
Location: 127.0.0.1
Distribution: Ubuntu 12.04 X86_64
Posts: 958

Rep: Reputation: 35
if i had files A B and C in directory dir
then
gzip * would end up with
A.gz B.gz and C.gz

where tar -czvf dir.tar.gz dir/

would end up with dir.tar.gs that contains all the files inside
 
Old 11-02-2009, 05:30 AM   #8
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Original Poster
Rep: Reputation: 16
I want all files and folders from public_html to one files.gz
 
Old 11-02-2009, 05:32 AM   #9
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Quote:
Originally Posted by ASTRAPI View Post
I want all files and folders from public_html to one files.gz
Then you can use
Code:
tar -czvf directory.tar.gz directory/
 
Old 11-02-2009, 12:14 PM   #10
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Original Poster
Rep: Reputation: 16
Ok but i don't think that i must specify the directory as i will run the command when i am already in that folder from ssh or not?

And one more:

Why i must have.tar before .gz?

Thanks
 
Old 11-02-2009, 01:01 PM   #11
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware, Mint
Posts: 1,252

Rep: Reputation: 205Reputation: 205Reputation: 205
The program gzip can compress separate files. When you want to compress a lot of files you have first to archive them in one file with tar and then compress it with gzip.

So you could use the commands:

tar cf archive.tar *

and:

gzip archive.tar

The resulting file has the name archive.tar.gz.

Instead of it you can use z switch in tar command to compress archive on the fly:

tar czf archive.tar.gz *

It's good to use in that case .tar.gz extension to remember in the future that it's compressed archive.

That command gives the same file:

tar czf archive.wow! *

but the extension .wow! means nothing so it'll be difficult to say in the future what kind of file is archive.wow!

If you don't like .tar.gz extension use .tgz one for gzip compressed tar archives.

The program bzip offers better compression than gzip:

tar cjf archive.tar.bz *

Instead of .tar.bz extension you can use .tbz one.

To uncompress these files use the commands:

tar xf archive.tar.gz

and:

tar xf archive.tar.bz
 
Old 11-02-2009, 02:18 PM   #12
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Original Poster
Rep: Reputation: 16
Thank you
 
  


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
How to Copy files from local directory to a particular directory using alias dynamics Linux - Newbie 7 09-11-2009 05:19 PM
How to copy files after search in array from this directory to another directory! phanvinhgiap Programming 4 01-04-2009 07:48 PM
Count the number of files in a directory and sub-directories within that directory soumyajit.haldar Linux - Software 4 03-20-2007 07:22 AM
Autozipping files from 1 directory & dropping them in other directory ??? amitsharma_26 Linux - Networking 5 10-22-2005 07:09 AM
Automatically Copying files from the ftp directory into the html directory swatward Linux - General 3 04-17-2005 11:55 PM


All times are GMT -5. The time now is 11:42 AM.

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