Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In the Finder, there is this wonderful ability to right click on a file or directory, select compress from the drop-down, and end up with a zipped file.

Is it possible to do the same thing from the terminal?

share|improve this question

2 Answers 2

Sure, it's called zip(1) – who would've thought?

This adds the file file to the archive file.zip:

zip file.zip file

Of course, to add more files, just add them as arguments to the command. Check out man zip for more options.

Often, you'll want to skip including those pesky .DS_Store files, for example compressing the whole folder folder into folder.zip:

zip -vr folder.zip folder/ -x "*.DS_Store"
share|improve this answer
    
whats the (1) after the word zip? –  Jacob Raccuia Jul 28 at 15:43
    
@JacobRaccuia See superuser.com/questions/297702/… –  slhck Jul 28 at 16:33

There is tar(1) and gzip (or bzip2 or lzma). Tar is used to roll a number of files into one archive, while the one of the other three is used to compress it.

On a command line, you will call tar with a couple of options to create an archive and gzip it.

E.g.:

tar -c -z -f myarchive.tar.gz -C /home/username Downloads

This willl -c reate a g -z ipped archive named -f ile from the -C hange-folder-to directory and will contain all files in the folder Downloads. The -C option is optional and the source-file arguments will be taken from the current folder if omitted.

For reference: tar tutorial

share|improve this answer

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.