Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Archiving multiple files in Unix using tar and gzip

Tags:

unix

gzip

tar

I have the requirement to archive multiple files keeping the original files using tar and gzip. I cannot take risks with the files I have.

For example, the files to be archived are:

ls
1.doc
2.doc
3.doc
4.xls
5.xls
6.xls

The expected output:

ls
1.doc
2.doc
3.doc
4.xls
5.xls
6.xls
archive.tar.gz

Where archive.tar.gz file contains all the doc and xls files.

like image 294
TechVolcano Avatar asked Oct 26 '25 09:10

TechVolcano


1 Answers

Did you try the command:

tar czf archive.tar.gz *.doc *.xls

Options here are:

  • c: Create
  • z: Gzip
  • f: Output file

To extract:

tar xzf archive.tar.gz

You can read the manual of the tar command for advanced options:

man tar
like image 106
Adagyo Avatar answered Oct 29 '25 08:10

Adagyo