I want to exclude the following file types:

  • epub
  • pdf
  • html (upper case too)
  • azw3
  • mobi
  • opf
  • txt

I have this so far which doesn't seem to work, i get an error saying "Incorrect Command Line".

7z e "-x!*.epub" "-x!*.pdf" "-x!*.html" "-x!*.azw3" "-x!*.mobi" "-x!*.txt" "-x!*.HTML" "-x!*.opf" *

I also tried the above command without double quotes.

I created the above command using info from here (for windows) but it doesn't seem to work under Linux.


7z only accepts a single archive within its arguments, but you're passing a wildcard which expands to the full content of the current working directory; anothe issue is that also the wildcards within the arguments will expand as well, either if non-quoted or double-quoted.

So you should only extract a single archive per command; you should remove the wildcard at the end, specify a single archive and single-quote the arguments:

7z e '-x!*.epub' '-x!*.pdf' '-x!*.html' '-x!*.azw3' '-x!*.mobi' '-x!*.txt' '-x!*.HTML' '-x!*.opf' archive.7z

To extract multiple archives at once however you can use multiple methods:

  • bash:
for archive in *.7z; do 7z e '-x!*.epub' '-x!*.pdf' '-x!*.html' '-x!*.azw3' '-x!*.mobi' '-x!*.txt' '-x!*.HTML' '-x!*.opf' "$archive"; done
  • find:
find . -maxdepth 1 -type f -iname "*.7z" -exec 7z e '-x!*.epub' '-x!*.pdf' '-x!*.html' '-x!*.azw3' '-x!*.mobi' '-x!*.txt' '-x!*.HTML' '-x!*.opf' {} \;
  • I have a lot of archives which need extracting, hence the use of the wildcard at the end to extract ALL archives. – daka Jul 7 '15 at 15:42
  • @sudoman Are you sure this is supported by 7z? Mind to try with a single archive? – kos Jul 7 '15 at 15:43
  • Tested, turns out 7zip doesn't actually allow the use of a wildcard to select multiple files within a given directory. – daka Jul 7 '15 at 15:48
  • @Ron I agree, but the problem here is that OP can't extract multiple archive at once; however upvoted your post – kos Jul 7 '15 at 16:33
  • @sudoman I've found another flaw in your original command, plus I added a couple of way to extract multiple archives at once – kos Jul 7 '15 at 17:23

From man 7z:

              Exclude filenames

To exclude file (or types) you can use the following command:

7z a -xr@exclude.txt backup.7z /whatever/dirs/or/files

Notice -xr instead of -x. The r indicates recursive so it can match excluded files in deep folder hierarchies

The file exclude.txt is a list separated by carriage returns like this:


If you want to exclude the full directory (you may have this extension file separated in directory)

 7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on ~/bkpFile_$(date +"%d_%b_%Y").1.7z /home/ubuntu/projectfile -mx0 '-xr!vendor' '-xr!view' '-xr!documents' 

Here, vendor , view, and documents directory has been excluded.

  • 1
    Why sudo? And what does this add to the existing answers? – muru Nov 2 '17 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.