Compress and extract files

With tar

On Unix based plattforms you can use the tar command for file compression and also for later uncompression.


$> tar -pczf web.tar.gz web/

With -h as the first parameter the real files instead symbolic links are compressed. So you can tar symbolic link targets.

To exclude files or folder, you can define –exclude=’fileOFolderPath’ directly after the tar command.

You can also pipe into tar like in the following example:

$> ls -lht | head -18 | awk '{print $9}'| xargs tar -pczf lastfiles.tar.gz --files-from -

This snippet takes the 18 most recent files and compresses them to a tar.gz file.


$> tar xvfz web.tar.gz

Useful Prarameters

To untar (extract) to another folder you can use the -C option.

With zip

But you probably prefer to use the zip / unzip command like on Microsoft Windows.


$> zip -9 -r -X folder_or_files_to_compress

Useful  prarameters

  • -9 (n) => integer value that specifies the compression level (0 == no compression – 9 == maximum compression)
  •  r => recursive
  • X => ignores invisible Mac resource files (bspw.: “_MACOSX”, “._Filename”, “.ds_store”)
  • o => override existing files
  • –symlinks => preserve the symlinks in the archive, so that after unpacking the filesystem, alle links work like before
  • >/dev/null => useful to silence the command (no output -> only errors)


$> unzip

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.