• We did not send an email asking for donations - please read this post.

How use gzip for compress one directory that contains *.conf in one file ficheiros.conf.gz


New Member
Jan 28, 2022
Reaction score
Hi i want compress the all *.conf in $ ~/sistema/Júpiter/luas/galileu for ficheiros.conf.gz but have a problem. I can't out of the folder nave. Is a requirement of exercise.

My directory is
$ ~/pjd07/nave
And i need compress the files this directory in same directory.

I try this:
$ gzip -c ficheiros.conf.gz ../sistema/jupiter/luas/galileu/*.conf

But doesn't work.

Can help me?


Well-Known Member
Apr 25, 2017
Reaction score
So, let me get this straight.
You are inside the directory ~/pjd07/nave?
Your .conf files are in ~/sistema/Júpiter/luas/galileu?
And you want to zip them up in the current working directory?
e.g. ~/pjd07/nave?

If so, the relative path you are using: ../sistema/jupiter/luas/galileu/*.conf is incorrect.
Because the sistema directory is two levels up in the file-system tree from ~/pjd07/nave, NOT one level.

So your relative path should be: ../../sistema/jupiter/luas/galileu/*.conf

Or, instead of using a relative path, you could just use the absolute path:

Your gzip command is also incorrect.
Because you are using the -c option - it will output the compressed text to the terminal's stdout.
So when you use the -c option, you need to redirect the output to a file.
So it should be something like this:
gzip -c ../../sistema/jupiter/luas/galileu/*.conf >> ficheiros.conf.gz
But I still don't think that will work properly, because gzip only works on single files. And it doesn't know anything about file-structure. So doing the above will merge all of the files together into a single file and you'll have no way of separating them.

So that would merge all of the files into a single compressed file called ficheiros.conf.gz, but you wouldn't be able to extract any of the files properly. They'd just come out as a single file when you decompress it.

So ideally, you really need to be using an archiver like tar, or zip, which does understand the file-structure.

So you could use tar with the -z option, to create a .tar.gz:
tar cvzf ficheiros.conf.tar.gz ~/sistema/jupiter/luas/galileu/*.conf
And that would create a .tar.gz in the current working directory containing the .conf files

Or perhaps just use zip:
zip ficheiros.conf.zip ~/sistema/jupiter/luas/galileu/*.conf
That creates a .zip file called ficheiros.conf.zip in the working directory, which contains all of the .conf files.
Last edited:
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation