Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'd like to compress and package everything, including files and folders in current directory, into a single ZIP file on Ubuntu.

What would be the most convenient command for this (and name of the tool needed to be installed if any)?

Edit: What if I need to exclude one folder or several files?

share|improve this question

1 Answer 1

up vote 12 down vote accepted

Install zip and use

zip -r foo.zip .

You can use the flags -0 (none) to -9 (best) to change compressionrate

Excluding files can be done via the -x flag. From the man-page:

-x files
--exclude files
          Explicitly exclude the specified files, as in:

                 zip -r foo foo -x \*.o

          which  will  include the contents of foo in foo.zip while excluding all the files that end in .o.  The backslash avoids the shell filename substitution, so that the name matching
          is performed by zip at all directory levels.

          Also possible:

                 zip -r foo foo -x@exclude.lst

          which will include the contents of foo in foo.zip while excluding all the files that match the patterns in the file exclude.lst.

          The long option forms of the above are

                 zip -r foo foo --exclude \*.o

          and

                 zip -r foo foo --exclude @exclude.lst

          Multiple patterns can be specified, as in:

                 zip -r foo foo -x \*.o \*.c

          If there is no space between -x and the pattern, just one value is assumed (no list):

                 zip -r foo foo -x\*.o

          See -i for more on include and exclude.
share|improve this answer
    
+1 What if I want to exclude some folder or file? –  Terry Li Dec 21 '11 at 21:33
1  
@TerryLiYifeng I edited my answer with info on that –  SkaveRat Dec 21 '11 at 21:42
    
Thank you very much. –  Terry Li Dec 21 '11 at 21:49
    
Thanks, good answer. –  Ishikawa Yoshi May 20 '13 at 15:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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