The 7-Zip command line is a text-based interface for the 7-Zip software that allows you to use 7-Zip commands and options directly from the command prompt or terminal window. It allows you to automate tasks and perform advanced operations using 7-Zip.
To use the 7-Zip command line, you will need to open a command prompt or terminal window and type the path to the 7-Zip executable file followed by the command and options that you want to use. For example:
"C:\Program Files\7-Zip\7z.exe" a -t7z archive.7z file_or_folder
This command will create a 7z archive called “archive.7z” containing the file or folder “file_or_folder”.
The 7-Zip command line supports a wide variety of commands and options that allow you to compress and decompress files and folders, create self-extracting (SFX) archives, apply password protection, and perform other tasks.
Table of Contents
- 7-Zip Command Line Examples
- How To Unzip a File in Command Prompt? (Windows)
- How To Unzip a File in Command Prompt on macOS?
- How To Unzip a File in Command Prompt on Linux?
- What Is 7-zip Switches?
- How to Use Switches In 7-Zip Command Line?
7-Zip Command Line Examples
Here are some examples of how 7-Zip can be used from the command line:
- To compress a file or folder using the highest level of compression:
7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on archive.7z file_or_folder
- To extract the contents of an archive:
7z x archive.7z
- To add a file to an existing archive:
7z u archive.7z file
- To create a self-extracting (SFX) archive that can be extracted without 7-Zip:
7z a -sfx archive.exe file_or_folder
- To list the contents of an archive:
7z l archive.7z
- To test the integrity of an archive:
7z t archive.7z
- To apply password protection to an archive:
7z a -p archive.7z file_or_folder
These are just a few examples of the many things that can be done with 7-Zip from the command line. For more information, you can refer to the 7-Zip documentation or use the 7z --help
command to see a list of available options.
How To Unzip a File in Command Prompt? (Windows)
To unzip a file using 7-Zip from the command line on Windows, you can use the 7z x
command followed by the name of the ZIP archive that you want to extract. Here is an example of how to unzip a file in the Command Prompt on Windows using 7-Zip:
- Open the Command Prompt by typing “cmd” into the Start menu search bar and pressing Enter.
- Navigate to the folder where you want to extract the ZIP archive. You can use the
cd
command to change directories. For example:
cd C:\Users\Username\Documents
- Type the following command to extract the ZIP archive:
7z x archive.zip
This will extract the contents of the ZIP archive to the current directory. If you want to extract the files to a specific folder, you can use the -o
option followed by the path of the destination folder. For example:
7z x archive.zip -oC:\Users\Username\Desktop\extracted
This will extract the contents of the ZIP archive to the “extracted” folder on the desktop.
How To Unzip a File in Command Prompt on macOS?
To unzip a file using 7-Zip from the command line on macOS, you can use the 7z x
command followed by the name of the ZIP archive that you want to extract. Here is an example of how to unzip a file in the terminal on macOS using 7-Zip:
- Open the terminal by opening the “Terminal” application from the “Utilities” folder in the “Applications” folder.
- Navigate to the folder where you want to extract the ZIP archive. You can use the
cd
command to change directories. For example:
cd /Users/Username/Documents
- Type the following command to extract the ZIP archive:
7z x archive.zip
This will extract the contents of the ZIP archive to the current directory. If you want to extract the files to a specific folder, you can use the -o
option followed by the path of the destination folder. For example:
7z x archive.zip -o/Users/Username/Desktop/extracted
This will extract the contents of the ZIP archive to the “extracted” folder on the desktop.
How To Unzip a File in Command Prompt on Linux?
To unzip a file using 7-Zip from the command line on Linux, you can use the 7z x
command followed by the name of the ZIP archive that you want to extract. Here is an example of how to unzip a file in the terminal on Linux using 7-Zip:
- Open a terminal window by pressing Ctrl+Alt+T or by searching for “Terminal” in the application launcher.
- Navigate to the folder where you want to extract the ZIP archive. You can use the
cd
command to change directories. For example:
cd /home/username/documents
- Type the following command to extract the ZIP archive:
7z x archive.zip
This will extract the contents of the ZIP archive to the current directory. If you want to extract the files to a specific folder, you can use the -o
option followed by the path of the destination folder. For example:
7z x archive.zip -o/home/username/desktop/extracted
This will extract the contents of the ZIP archive to the “extracted” folder on the desktop.
What Is 7-zip Switches?
7-Zip is a file archiver that can be used from the command line or from a graphical user interface (GUI). It supports a number of different switches or options that allow you to customize its behavior and perform advanced tasks. Here are some examples of 7-Zip switches that you can use:
-t
: Specify the type of archive to create. For example,-t7z
creates a 7z archive, while-tzip
creates a ZIP archive.-m
: Set the compression method to use. For example,-mx=9
sets the compression level to maximum.-mmt
: Set the number of CPU threads to use. For example,-mmt=4
uses four CPU threads.-o
: Set the output directory for the extracted files. For example,-oC:\extracted
extracts the files to the “extracted” folder on the C drive.-p
: Set the password for an encrypted archive.-sfx
: Create a self-extracting (SFX) archive.-v
: Create a multivolume archive.
Full List of Switches
Here is a list of all of the 7-Zip switches that are available in the latest version of 7-Zip:
7z
command:
a
: Add files to an archive.b
: Set the volume size for multivolume archives.d
: Delete files from an archive.e
: Extract the contents of an archive.h
: Display help information.i
: Include filenames in the archive.l
: List the contents of an archive.r
: Add files to an archive recursively.t
: Test the integrity of an archive.u
: Update the files in an existing archive.x
: Extract the contents of an archive with full paths.
a
, d
, e
, l
, r
, t
, u
, x
commands:
-ai[r[-|0]]]{@listfile|!wildcard}
: Include archives.-ax[r[-|0]]]{@listfile|!wildcard}
: Exclude archives.-bd
: Disable percentage indicator.-i[r[-|0]]]{@listfile|!wildcard}
: Include filenames.-m{Parameters}
: Set compression method.-o{Directory}
: Set output directory.-p{Password}
: Set password.-r
: Recurse subdirectories.-scc{UTF-8|WIN|DOS}
: Set charset for list files.-scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS}
: Set charset for console input/output.-sfx[{name}]
: Create SFX archive.-si[{name}]
: Read data from stdin.-slt
: Show technical information for l (List) command.-so
: Write data to stdout.
How to Use Switches In 7-Zip Command Line?
To use switches or options with 7-Zip, you will need to specify them along with the 7-Zip command when using 7-Zip from the command line. Here is an example of how to use a switch with the 7z
command:
7z a -t7z -mx=9 archive.7z file_or_folder
This command creates a 7z archive called “archive.7z” containing the file or folder “file_or_folder” using maximum compression. The -t7z
switch specifies the type of archive to create, while the -mx=9
switch sets the compression level to maximum.
To use multiple switches with a single command, you can simply list them one after the other, separated by a space. For example:
7z x -oC:\extracted -psecret archive.zip
This command extracts the contents of the “archive.zip” file to the “extracted” folder on the C drive, using the password “secret”. The -o
switch specifies the output directory, while the -p
switch sets the password.
Keep in mind that the syntax for the switches and options may vary depending on the version of 7-Zip that you are using. Be sure to consult the documentation or use the 7z --help
command to get the correct syntax for the version of 7-Zip that you are using.