'Archiving multiple files in Unix using tar and gzip

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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source