tag 41931 +notabug close 41931 thanks Hello Saleh,
Saleh Abdelkerim wrote: > Hello, please excuse me I would like to know how we can compress a set of > files into a file.gz online command under linux because I want to customize > a linux system and I had a problem compressing several files in format gz. The normal tool to use to compress a set of files is 'tar'. If you wish to compress a set of files then use tar to do so. Then compress the tar file with gzip. tar cvf - ./file1 ./file2 ./file3 ./file4 | gzip > ./files.tar.gz Using tar the above options "cvf -" mean this. c create (instead of appending or other possibilities) v verbosely print out each file as it is processed f - file to output into, "-" is stdout (standard output) Then it is piped to the next command "| gzip" which compresses the tar file. The output is then redirected to a file. By convention and tradition the file name would be .tar.gz indicating that it is a gzip'd tar file. This is so common of an action that tar has an option specifically for passing the output through gzip as a typing aide. It does the exact same thing as the above. But it does it internally in order to save typing. tar cvzf ./files.tar.gz ./file1 ./file2 ./file3 ./file4 And reading the output from the tar file back and expanding those files is done similarly. gunzip < ./files.tar.gz | tar xvf - This also has a typing short cut because it is so often done. tar xvzf ./files.tar.gz To list what is in the files.tar.gz file. gunzip < ./files.tar.gz | tar tvf - tar tvzf ./files.tar.gz In my examples I used ./file1 ./file2 ./file3 ./file4 as my example. The command line shell will also expand wildcards. And also tar will read directories. Therefore using wildcards and directories are also possible. tar cvzf ./files.tar.gz ./adirectory57 tar cvzf ./files.tar.gz ./*.txt ./*.html Careful writing an output file into the directory one is compressing. tar cvzf ./files.tar.gz . # WARNING! Do not do this. Tools that read directories and writing output to the directory might start reading their output file endlessly! In this case make sure the output file is in a different directory. tar cvzf ../files.tar.gz . # Okay tar cvzf /tmp/files.tar.gz . # Okay Note that these are but one way out of many ways to do things. There are many roads to the same place. But these are the most common and most often way to compress many files into one compressed bundle. Hope that helps! Bob