Zip And Unzip Directories

Make Directory

mkdir regiment_data

Make Files In Directory

touch regiment_data/battles.txt regiment_data/regiment.txt

Zip Directory

In the code below, we compress (zip) the regiment_data directory into the file regiment.zip. Note that -r means that we want to not only zip the directory but also its contents (which is almost always the case) .

zip -r regiment.zip regiment_data

  adding: regiment_data/ (stored 0%)
  adding: regiment_data/battles.txt (stored 0%)
  adding: regiment_data/regiment.txt (stored 0%)

View Directory Contents

ls -l
total 8
drwxrwxr-x 2 chris chris 4096 Jul 31 13:39 regiment_data
-rw-rw-r-- 1 chris chris  536 Jul 31 13:39 regiment.zip

Delete Directory

rm -rf regiment_data
total 8
drwxrwxr-x 2 chris chris 4096 Jul 31 13:39 regiment_data
-rw-rw-r-- 1 chris chris  536 Jul 31 13:39 regiment.zip

Unzip Directory

unzip regiment.zip
Archive:  regiment.zip
   creating: regiment_data/
 extracting: regiment_data/battles.txt
 extracting: regiment_data/regiment.txt

View Directory Contents

ls -l
total 8
drwxrwxr-x 2 chris chris 4096 Jul 31 13:39 regiment_data
-rw-rw-r-- 1 chris chris  536 Jul 31 13:39 regiment.zip