How can I zip a file and save it in another directory using the command line? I have no space left in directory (100% full).

zip -r  /path/to/save/destination_folder.zip /path/to/folder
  • /path/to/folder - path to your source folder

  • /path/to/save/destination_folder.zip - path to destination zip-file

  • r - recurse into directories

Also you can just type zip in putty command prompt to get help information

Please, notice I wrote information for *nix systems. For Win it could be differ.


Quickly looking at the man pages for tar, we can set the output file with -f

I usually use something of the form:

tar -a -cf filename.tar.bz2 input_fname.txt

Then you can specify your filepath as part of your filename to output. For example /mnt/drive_1/output.tar.bz2 or ../../output.tgz would work as a filename. Then you would end up with your compressed file at that place.


  • a: auto compress: Uses your given file type to figure out what to do.
  • c: compress: Tells it to compress instead of decompressing
  • f: set a file name: allows you to specify your file and file path. You can also give relative path names as well.

I'm hoping that tar compression just puts everything at the output file and doesn't do anything in your directory. Try it and see if it works though.

  • While I gave examples with tar.bz2 and tgz, it will work with the zip extension as well. – Evan Jul 6 '14 at 2:39
  • 1
    'c' is not the compression option, it is the "create" option. zip is not supported by GNU tar. zip is both an archiver and a compression format. – James K Polk Jul 6 '14 at 16:43
  • I don't know if we have different versions of tar, but in my man pages, under the -a, --auto-compress option, it says that it ignore things like -j if it doesn't work with the file extension. In my man pages for creating a new archive with the zip format: "tar -a -cf archive.zip source.c source.h creates a new archive with zip format," along with some other features. You are right that it is to create an archive and not compress one though. – Evan Jul 6 '14 at 16:53
  • I was going by GNU tar – James K Polk Jul 6 '14 at 16:56
  • When I run "tar -a -cf archive.zip source.c source.h" with GNU tar I get an uncompressed tar archive, not a zip archive. – James K Polk Jul 6 '14 at 17:03

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.