Skip to main content

Zip and unzip in Linux

 Zip and unzip in Linux

We can use the commands to zip and unzip the files or folders in Linux. Zip and unzip and such useful commands.

The usage of the commands are described below.

Zipping

Create a zip file for a single file

zip targetZipFilename.zip filetoZip.txt

Add multiple files to the new zipfile

zip targetZipFilename.zip filetoZip-1.txt filetoZip-2.txt

Note : We can use wildcards for the filenames as needed.

Add a file to existing zip file 

zip -u existingZipFilename.zip filetoZip.txt

Remove  single file from a zip file

zip -d existingZipFilename.zip filetoRemoveFromZip.txt

Zip directories and the contents

zip -r ZipFilename.zip ./FolderInPWDToZip

Note : -r is for recursive file selection.

To zip everything in the present working directory

zip -r ZipFilename.zip ./*

Unzipping 

The command without any arguments will unzip the contents to present folder. No additional folders will be created on extraction.

Basic unzip 

unzip zippedFile.zip

Extract to a specified folder 

unzip zippedFile.zip -d /targetFolder

Note : create the folder if the target folder does not exist.

Comments

Popular posts from this blog

Public private key based login to Unix computer

Public private key based login to Unix computer We know that we can login to a Unix system in several ways. One drawback with username password mode is that there will be requirement to update the password frequently. In such cases, we go for the public key based login.  Required software 1. Putty and puttygen Putty can be downloaded from the download page of  https://www.putty.org/ The downloaded zip contains both putty and puttygen. 2. Winscp This is an optional software which gives a window when dealing with ssh, ftp, sftp connections. This can be downloaded from their official site. https://winscp.net/eng/download.php How it works In the public key based login, we will generate a public key and corresponding private key pair. We can optionally protect the private key using a password so that if someone gets your private key, they wont be able to put it into real use [The secret would be needed for loading your private key to the ssh client]. Process Create the publ...

PDF files : Merge pdf files into one , extract the pages into new one

 Today, we will take a look into he pdf file management. Many a times we come across situations where  1. We have to extract certain pages of a large pdf file. 2. We have merge several pdf files into a single pdf file. We are covering the basic usage below. We are using Ubuntu Linux for this exercise. Merge several files into a single file 'Pdfunite' is the utility that I will be using today. In my example, I have 3 input files (pdf1.pdf, pdf2.pdf, pdf3.pdf)   Place all the files to be merged in a folder. Use the terminal to navigate to the folder. Execute the command as below: pdfunite is the utility, then we list out all the files in the sequence it has to be added to the resulting file. The last name is the name of the resulting file. The file will be created by the utility. pdfunite pdf1.pdf pdf2.pdf pdf-result.pdf  Now you can see that there is a new large file created using the given input pdf files.  Extract certain pages from a PDF file I am using the 'p...

Linux commands - Network related

 Linux commands - Network related This write up is a collection of some of the most commonly used linux commands used in the network related work. This is a short note and not a complete reference. 1. ifconfig / ip  This command is used to find the network IP related information of the server. 'ip' is the latest update or the current command to be used on the latest version of the OS. 2. ping destination_host  This is used to ping the destination server. Bacially, it will simply check the connection to the target. You can interrupt the command with 'ctrl+c'. 3. telnet host port  This command is used to connect to a specific port on the destination server. This works better than the ping command as this will attemp to connect to the specified port. You can interrupt the command with 'ctrl+c'. In some cases, when 'crtl+c' is not closing the telnet session, please use 'ctrl+]' and then enter 'close'. 4. nslookup google.com  This is the shor...