CLI Zip Cheatsheet

# Instead use the -r option

```
$ zip -r src.zip ./src/
§ zip src.zip ./src/**/*  <-- Dont do this - Globs won't work as expected
```
  
# List zip content  (unzip -l)
  
```
  $ unzip -l pod_until_2022-12-29.zip > log.txt  
```

# List zip content while outputing to external file 
Ideal wen zip contains to many files  
```
  $ unzip -l pod_until_2022-12-29.zip > log.txt  
```

# Look for a particular file inside the zip
```
  $ unzip -l pod_until_2022-12-29.zip | egrep file-name-to-search
```


# Appending files/folders to a particular zip

```
# cd into folder where files are kept
# then run: 
$ zip -ur path/to/existing.zip ./folder1 ./folder2 ./file1.txt
```


Creates the archive data.zip and puts all the files in 
the current directory in it in compressed form, type:

```
$ zip data *
```



To zip up an entire directory (including all subdirectories), type the following command:

```
$  zip -r data *
```

## unziping files/directories examples

To use unzip to extract all files of the archive pics.zip into the current directory & subdirectories:

```
$ unzip  pics.zip
```

You can also test a .zip printing only a summary message 
indicating whether the archive is OK or not:

```
$ unzip -tq my.zip
```

To extract the file called cv.doc from pics.zip:

```
$ unzip pics.zip  cv.doc
```

To extract all files into a particular folder:

```
$ unzip pics.zip  -d /tmp
```


Other references:
  • http://eriklievaart.com/cheat/linux/io/zip.html

Leave a Reply

Close Menu