-x (Exclude filenames) switch
Specifies which filenames or wildcarded names must be excluded from the operation.
Multiple exclude switches are supported.
Syntax
-xtd
-x[<recurse_type>][<mark_type>][<wildcard_type>]<file_ref>
<recurse_type> ::= r[- | 0]
<mark_type> ::= m[- | 2]
<wildcard_type> ::= w[-]
<file_ref> ::= @{listfile} | !{wildcard}
See -i (Include) switch description for information about
-x option parameters.
-xtd : to exclude directory metadata records from processing.
But it still can process all files in any directory and in subdirectories.
If switch -xtd is specified, 7-zip doesn't process records that represent
metadata properties of directory itself: name, timestamps and attributes
of directory.
So the archive created with -xtd will contain only records for files.
But these files still can reside in different directories and subdirectories.
Examples
7z a -tzip archive.zip *.txt -x!temp.*
adds to the archive.zip all
*.txt files,
except temp.* files.
7z a archive.7z Folder1\ -xr!*.png
adds to the archive.7z all
files from Folder1 and its subfolders,
except *.png files.
Commands that can be used with this switch
a (Add) ,
d (Delete) ,
h (Hash) ,
e (Extract) ,
l (List) ,
t (Test) ,
rn (Rename) ,
u (Update) ,
x (Extract with full paths)
See also
Switches:
-r (Recurse) ,
-i (Include)
Notes from this site
Not part of the 7-Zip manual. Written by this site; examples checked with 7-Zip 26.04.
Quick examples
The official Linux/macOS console binary is 7zz; on Windows use 7z. Single quotes keep the shell from expanding * and !; unquoted, zsh stops with no matches found. In Windows cmd.exe leave the quotes out: 7z a backup.7z project\ -xr!node_modules.
# skip a folder and *.log files at any depth
7zz a backup.7z project/ -xr'!node_modules' -xr'!*.log'
# skip only the top-level project/build (not project/src/build)
7zz a backup.7z project/ -x'!project/build'
# skip .git folders at any depth (run from inside the folder)
7zz a backup.7z . -xr'!.git'
# skip names listed in exclude.txt
7zz a backup.7z project/ -xr@exclude.txt
# skip files while extracting
7zz x backup.7z -oout -x'!project/docs/*'
# check the result before you rely on it
7zz l -ba backup.7z
Patterns match the path as it will be stored, starting with the folder name you typed (project/build), not the full disk path. Sample exclude.txt: one pattern per line, no quotes and no !. In our test this excluded all three at every depth.
node_modules
*.log
build
What r and m do
r: the pattern may match at any depth. -xr'!build' removed both project/build and project/src/build. r0 recurses only for wildcard names: -xr0'!*.log' removed the logs, -xr0'!build' removed nothing.
m: a folder pattern must end with /. -xrm'!build/' removed the folders, -xrm'!build' removed nothing.
-xtd: leave out the entries for folders themselves; files inside them are still stored. In our test the listing had no D.... lines but every file kept its project/... path.
Common mistakes
Plain -x'!*.png' matches only one path level. It left project/docs/p.png and project/src/sub/q.png in the archive; -xr'!*.png' removed both.
-x@exclude.txt without r removes only top-level names: it dropped build and top.log but left src/build and src/b.log. Use -xr@exclude.txt.
For one exact folder use -x'!project/build' without r. With -xr'!project/build' we also lost project/src/build.
No space inside a switch: -xr'!*.log', not -xr '!*.log'. Repeat -x for several patterns.
Want to keep only some file types? Do not exclude everything else; use -i .
See also -r , -ssc (case) and list files .