Create .7z File in Linux

Last updated on Dec 28, 2019 in Linux

7zip is a compression/decompression utility program in Linux. With 7zip you can compress single files and folders. This tutorial is about to create a 7z from a single file. To compress a whole folder, check article Create .7z File From Folder Recursively in Linux.

If you want to compress a file myfile.txt, type following command:

$ 7za a myfile.7z myfile.txt

The a stands for add. This will create a 7z file named myfile.7z in the same folder. If the file exists, the myfile.txt is appended to the archive.

You may add multiple files to the same 7z as well:

$ 7za a myfile.7z myfile.txt another.txt another2.txt

In order to view files in a 7z file, check this article: See List of Files in .7z File in Linux.