Zip Without Compression – Windows, Linux, MacOS

If you want to store a big folder as a single file, so it could be easily uploaded somewhere or shared with someone, you can create a simple zip archive from it.

To avoid wasting a time and resources on compression and decompression, this zip archive can be created without compression.

In this short note i will show how to create a zip file without compression from the command line on Windows, Linux and MacOS. (more…)

HowTo: Create a Password Protected ZIP File in Linux

This is a small note that describes how to encrypt and decrypt a ZIP file from the Linux command line.

I’ll show how to create a password protected ZIP archive from one or several unprotected files or folders.

Warning! The standard ZIP encryption is very weak and could be cracked easily.

Password Protected ZIP File in Linux

Create an encrypted ZIP file secure.zip from some file:

$ zip --encrypt secure.zip file
Enter password: 
Verify password: 
  adding: file (deflated 8%)

Create password protected ZIP archive secure.zip from the several files:

$ zip --encrypt secure.zip file1 file2 file3
Enter password: 
Verify password: 
  adding: file1 (stored 15%)
  adding: file2 (deflated 30%)
  adding: file3 (deflated 45%)

Create an encrypted ZIP archive secure.zip from a folder /var/log/:

$ zip --encrypt -r secure.zip /var/log/
Enter password: 
Verify password: 
  adding: var/log/ (stored 0%)
  adding: var/log/dmesg.0 (deflated 74%)
  adding: var/log/dpkg.log.9.gz (deflated 0%)
  adding: var/log/samba/log.asc-nb (deflated 96%)
***

Use the following command to uncompress a ZIP file:

$ unzip secure.zip
Enter password:
***

Encrypt and Decrypt ZIP Archive in Linux

You were interactively prompted for the password in the examples above.

If you want to create a password protected ZIP file from some shell script, you may want to do it non-interactively.

This method is more insecure, as the password is entered as plain text.

You can easily encrypt and decrypt ZIP files from the Linux command line without being prompted for the password.

Do it as follows:

$ zip -P passw0rd secure.zip file
$ zip -P passw0rd secure.zip file1 file2 file3
$ zip -P passw0rd -r secure.zip /var/log/

Uncompress a password protected ZIP archive:

$ unzip -P passw0rd secure.zip

HowTo: Extract Archives [tar|gz|bz2|rar|zip|7z|tbz2|tgz|Z]

A small note about how to unpack and uncompress the most popular types of archives from the Linux command line.

Unpack [tar|tar.gz|tgz|tar.bz2|tbz2] Files in Linux

Use the following commands to extract TAR archives compressed with GZIP and BZIP2:

$ tar xvf file.tar
$ tar xvzf file.tar.gz
$ tar xvzf file.tar.tgz
$ tar xvjf file.tar.bz2
$ tar xvjf file.tar.tbz2

Uncompress [zip|rar|bz2|gz|Z|7z] Files in Linux

Use the following commands to uncompress archives or files, compressed with ZIP, GUNZIP, RAR, BUNZIP2, COMPRESS and 7Z programs:

$ unzip file.zip
$ gunzip file.gz
$ unrar x file.rar
$ bunzip2 file.bz2
$ uncompress file.Z
$ 7z x file.7z

Extract Archives with Shell Function

You can create a bash shell function as follows (add to your ~/.bashrc):

function extract {
 if [ -z "$1" ]; then
    # display usage if no parameters given
    echo "Usage: extract ."
 else
if [ -f $1 ] ; then
        # NAME=${1%.*}
        # mkdir $NAME && cd $NAME
        case $1 in
          *.tar.bz2) tar xvjf ../$1 ;;
          *.tar.gz) tar xvzf ../$1 ;;
          *.tar.xz) tar xvJf ../$1 ;;
          *.lzma) unlzma ../$1 ;;
          *.bz2) bunzip2 ../$1 ;;
          *.rar) unrar x -ad ../$1 ;;
          *.gz) gunzip ../$1 ;;
          *.tar) tar xvf ../$1 ;;
          *.tbz2) tar xvjf ../$1 ;;
          *.tgz) tar xvzf ../$1 ;;
          *.zip) unzip ../$1 ;;
          *.Z) uncompress ../$1 ;;
          *.7z) 7z x ../$1 ;;
          *.xz) unxz ../$1 ;;
          *.exe) cabextract ../$1 ;;
          *) echo "extract: '$1' - unknown archive method" ;;
        esac
else
echo "$1 - file does not exist"
    fi
fi
}

Source: https://github.com/xvoland/Extract

Reload .bashrc file.

$ . ~/.bashrc

Now use extract command for unpacking and uncompressing the most popular archive types:

$ extract file.rar
$ extract file.tar.gz2
$ extract file.7z

HowTo: Download and Extract (untar) TAR Archive with One Command

Use one of the following commands to download and extract (untar) [tar], [tar.gz] or [tar.bz2] files “on fly”, without saving archive themselves.

  • No temporary files;
  • No Extra output;
  • Minimal file space and memory usage.

The following methods are most fast and compact for downloading and unpacking archives.

Download and Extract Archives with WGET

$ wget http://example.com/archive.tar -O - | tar -x
$ wget http://example.com/archive.tar.gz -O - | tar -xz
$ wget http://example.com/archive.tar.bz2 -O - | tar -xj

Download and Extract Archives with CURL

$ curl http://example.com/archive.tar | tar -x
$ curl http://example.com/archive.tar.gz | tar -xz
$ curl http://example.com/archive.tar.bz2 | tar -xj
Option Description
-x extract files from an archive
-z decompress the contents of the compressed archive created by gzip program [tar.gz]
-j decompress the contents of the compressed archive created by bzip2 program [tar.bz2]

Untar Tar.gz – Linux Tar Command – HowTo: Extract Tar File

Most of the Linux files that can be downloaded from the Internet are compressed with a tar, tar.gz and tar.bz2 compression formats and it is important to know how to extract such files.

The following article will help you to extract (unpack) and uncompress (untar) – tar, tar.gz and tar.bz2 files from the Linux command line.

You will learn how to list the contents of a tar archive without unpacking it and how to extract only a single file or a single directory. (more…)