How to unzip a zip file from Terminal (Google Cloud Shell)
This tutorial guides you how to unzip a zip file in Google Cloud Shell of Google Cloud Platform using unzip command.
Unzip
Unzip is a utility used to list, test and extract compressed files in ZIP archive. Note, unzip is installed in most of the linux distributions. If not installed then you can install unzip on Ubuntu and Debian using the following command.
$ sudo apt install unzip
To install unzip on CentOS and Fedora, run the following command
$ sudo yum install unzip
You can check the installation by running unzip command.
@cloudshell:~ (sneppets-gcp)$ unzip UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP. Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir] Default action is to extract files in list, except those in xlist, to exdir; file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage). -p extract files to pipe, no messages -l list files (short format) -f freshen existing files, create none -t test compressed archive data -u update files, create if necessary -z display archive comment only -v list verbosely/show version info -T timestamp archive to latest -x exclude files that follow (in xlist) -d extract files into exdir modifiers: -n never overwrite existing files -q quiet mode (-qq => quieter) -o overwrite files WITHOUT prompting -a auto-convert any text files -j junk paths (do not make directories) -aa treat ALL files as text -U use escapes for all non-ASCII Unicode -UU ignore any Unicode fields -C match filenames case-insensitively -L make (some) names lowercase -X restore UID/GID info -V retain VMS version numbers -K keep setuid/setgid/tacky permissions -M pipe through "more" pager See "unzip -hh" or unzip.txt for more help. Examples: unzip data1 -x joe => extract all files except joe from zipfile data1.zip unzip -p foo | more => send contents of foo.zip via pipe into program more unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
unzip a zip file from Terminal (Google Cloud Shell)
The unzip command will extract all the files from specified ZIP archive to the current directory. And to extract a ZIP archive to some specific directory you need to have permissions on that directory.
For example, let’s say you have downloaded some source code from git in your current working directory. To unzip springbootdemo.zip file to the current directory (/home/sneppets) you simply run the following command.
6@cloudshell:~ (sneppets-gcp)$ ls springbootdemo.zip @cloudshell:~ (sneppets-gcp)$ pwd /home/sneppets @cloudshell:~ (sneppets-gcp)$ unzip springbootdemo.zip Archive: springbootdemo.zip creating: springbootdemo/ inflating: springbootdemo/.classpath inflating: springbootdemo/.project creating: springbootdemo/.settings/ extracting: springbootdemo/.settings/org.eclipse.core.resources.prefs inflating: springbootdemo/.settings/org.eclipse.jdt.core.prefs inflating: springbootdemo/.settings/org.eclipse.m2e.core.prefs creating: springbootdemo/deployment/ creating: springbootdemo/deployment/docker/ inflating: springbootdemo/deployment/docker/docker-compose-build.yml inflating: springbootdemo/deployment/docker/docker_push creating: springbootdemo/deployment/helm/ creating: springbootdemo/deployment/helm/spring-hello/ inflating: springbootdemo/deployment/helm/spring-hello/.helmignore inflating: springbootdemo/deployment/helm/spring-hello/Chart.yaml creating: springbootdemo/deployment/helm/spring-hello/charts/ creating: springbootdemo/deployment/helm/spring-hello/templates/ inflating: springbootdemo/deployment/helm/spring-hello/templates/deployment.yaml inflating: springbootdemo/deployment/helm/spring-hello/templates/ingress.yaml inflating: springbootdemo/deployment/helm/spring-hello/templates/NOTES.txt inflating: springbootdemo/deployment/helm/spring-hello/templates/service.yaml inflating: springbootdemo/deployment/helm/spring-hello/templates/serviceaccount.yaml creating: springbootdemo/deployment/helm/spring-hello/templates/tests/ inflating: springbootdemo/deployment/helm/spring-hello/templates/tests/test-connection.yaml --------------- --------------- ---------------
@cloudshell:~ (sneppets-gcp)$ ls springbootdemo.zip springbootdemo @cloudshell:~/springbootdemo (sneppets-gcp)$ ls deployment docker-compose.yml Dockerfile pom.xml spring-hello
To unzip a ZIP file to different directory instead of current directory, you need to use “-d” switch as shown below
$ unzip springbootdemo.zip -d /path/to/different_directory
Also See
- Cloud Interconnect is a direct, private connection for extending corporate network to Google Cloud
- Google Virtual Private Cloud (VPC) Networks Lab Exercise
- Create GCP project on Google Cloud Platform
- Compute Resources for VMware vSphere Cloud Infrastructure