LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can i .gz all files in a directory? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-gz-all-files-in-a-directory-766061/)

ASTRAPI 11-01-2009 04:26 PM

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

smeezekitty 11-01-2009 04:29 PM

what about gzip *.* ?

repo 11-01-2009 04:30 PM

try
Code:

tar -czvf directory.tar.gz directory/

w1k0 11-01-2009 04:31 PM

or simply gzip * ?

smeezekitty 11-01-2009 04:32 PM

we do not know if the orignal poster wants each one gziped indiviually or all in one.

jschiwal 11-01-2009 04:36 PM

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

dasy2k1 11-02-2009 02:28 AM

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

ASTRAPI 11-02-2009 04:30 AM

I want all files and folders from public_html to one files.gz

repo 11-02-2009 04:32 AM

Quote:

Originally Posted by ASTRAPI (Post 3741001)
I want all files and folders from public_html to one files.gz

Then you can use
Code:

tar -czvf directory.tar.gz directory/

ASTRAPI 11-02-2009 11:14 AM

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 :)

w1k0 11-02-2009 12:01 PM

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

ASTRAPI 11-02-2009 01:18 PM

Thank you :)


All times are GMT -5. The time now is 07:00 AM.