top of page
taitaigramsentca

Unzip a file in unix command: A step-by-step guide with examples



Note: Some graphical interfaces include a tool for managing tar.gz files without the command-line. Simply right-click the item you want to compress, mouseover compress, and choose tar.gz. You can also right-click a tar.gz file, mouseover extract, and select an option to unpack the archive.


Many answers here mention tools that require installation, but nobody has mentioned that two of Ubuntu's scripting languages, Perl and Python, already come with all the necessary modules that allow you to unzip a zip archive, which means you don't need to install anything else. Just use either of the two scripts presented below to do the job. They're fairly short and can even be condensed to a one-liner command if we wanted to.




unzip a file in unix command



tar is an acronym for Tape Archive. tar command is used toManipulates archives in Linux/Unix. System administrators uses tarcommand frequently to rip a bunch of files or directories into highlycompressed archive which are called tarball or tar, bzip andgzip in Linux/Unix system.


4.-r Option: To zip a directory recursively, use the -r option with the zip command and it will recursively zips the files in a directory. This option helps you to zip all the files present in the specified directory.Syntax:


6.-v Option: Verbose mode or print diagnostic version info. Normally, when applied to real operations, this option enables the display of a progress indicator during compression and requests verbose diagnostic info about zip file structure oddities.When -v is the only command line argument, and either stdin or stdout is not redirected to a file, a diagnostic screen is printed. In addition to the help screen header with program name, version, and release date, some pointers to the Info-ZIP home and distribution sites are given. Then, it shows information about the target environment (compiler type and version, OS version, compilation date and the enabled optional features used to create the zip executable.Syntax :


use password to decrypt encrypted zipfile entries (if any). THIS IS INSECURE! Many multi-user operating systems provide ways for anyuser to see the current command line of any other user; even onstand-alone systems there is always the threat of over-the-shoulderpeeking. Storing the plaintext password as part of a command line inan automated script is even worse. Whenever possible, use thenon-echoing, interactive prompt to enter passwords. (And wheresecurity is truly important, use strong encryption such as Pretty GoodPrivacy instead of the relatively weak encryption provided by standardzipfile utilities.)


To make it work, you need to include the *.zip in quotes because whenever you use a wildcard (*), the shell itself will expand that and pass the results to the program. This is because, unlike most programs in UNIX, unzip cannot take more than one file at a time.


A tarball or tarfile is name of group of files that are bundled together. These files are produced by the command tar. Tar itself does not support compression directly. It is often used with a compression utility such as Gzip or Bzip2 to space disk space. These compression utilities generally only compress a single file, so they are used in combination with Tar, which can produce a single file from many files.If the tarfile is compressed using Gzip compression utility, the tarball file will end with TAR.GZ. Using the Gunzip command, Linux users can uncompress TAR.GZ or TGZ files. Windows users can also create and expand tarball files using the 7-Zip compression utility.


GZ and TGZ files are considered file compression and archiving standards for Linux systems. Therefore, knowing how to create and uncompress GZ and TAR.GZ files can help you accomplish different website administration tasks, including creating backups and restoring websites from them. In this article, we will learn what Gzip and Tar utilities are and how to create and unzip GZ and TGZ/TAR.GZ files in Linux.


Tar does not change file system attributes such as permissions or ownership of the files included in a tarball; it saves them in an archive. Even after an archive has been created, you can still add or remove files from it or manipulate the filenames unless the archive has been compressed. The tar command is used to manage TAR and TAR.GZ files on a Linux system, including their creation, modification, and extracting files from them.


Tar supports multiple compression methods, the most common of them are the Gzip/Gunzip and Bzip2/Bunzip2 compression utilities. Using Tar together with Gzip for file compression has become the best file archiving solution for Linux.


Gzip is the most popular file compression utility for Linux systems which can be used alone to compress individual files. The Gzip and Gunzip commands compress a file, resulting in the new compressed version of it being created while the original file is removed by default. Files compressed with Gzip will have the GZ file extension. Therefore, when paired with Tar, the compressed archive will be saved as a TAR.GZ or TGZ file.


Tar and Gzip/Gunzip commands allow system administrators to create and unzip GZ and TGZ files. Like many other Linux utilities, they provide a set of flags that help you choose the options your need to use the functionality of the commands better to achieve specific goals. Gzip/Gunzip and Tar are installed by default on most Linux distributions, so all you need is SSH access and basic knowledge of the Linux command line interface.


Gzip and Gunzip commands can be used to unzip GZ files in Linux, except for compressed Tar archives. Although a TAR.GZ file is a TAR archive compressed by Gzip, only the Tar command will allow you to uncompress and extract files from it.


As we discussed, you can compress an individual file by creating a new version of it with the GZ file extension while keeping the same file permissions and ownership. By default, the original file will be removed, so you will need to unzip the GZ file to continue using it. However, this behavior can be changed. Below we will compress three files from the current working directory using Gzip compression.


We are keeping the original files using the -k flag and can see the percentage reduction and the names of the files processed as the command runs by using the -v option. Three new GZ files will be created in the directory due to the command above. The -k flag might be unavailable in some cases, so we will need to use the -c option to keep the original file.


We can use the -c flag to make the Gzip command usage more flexible. For example, we can use it to change the directory the new compressed file will be saved to and to change its name.


You can use the zcat command in Linux to view the contents of a compressed file without unzipping it. It works for all compression utilities, including Gzip.


You can unzip GZ files in Linux by adding the -d flag to the Gzip/Gunzip command. All the same flags we used above can be applied. The GZ file will be removed by default after we uncompressed it unless we use the -k flag. Below we will unzip the GZ files we compressed in the same directory.


The tar command is used to create and unzip the TGZ files on a Linux system. You can choose to unzip the whole archive or extract only the selected files or directories. Below we will learn how to unzip TAR.GZ files from the command line using different flags.


Using the first command, we have created a Gzip-compressed Tar archive of the whole my_directory folder and placed it in the /home/temp directory. When using the second command, the tar_files_archive.tar.gz file will be saved to the current working directory and will only contain the three files we specified to be included.


You can Untar Gzip-compressed Tar archives using the -x (extract) flag the Tar command provides. Again, you can specify what directory you would like to extract the archived files to, as Tar will place all the contents of the TGZ file to the current working directory by default.


The zip command is used to compress files for ease and portability, on Linux/Unix operating systems. There are various other ways to compress your files, but the zip command is among the most popular.


  • >CL_ABAP_GZIP CL_ABAP_GZIP won't work because it only does compression/decompression. It doesn't acutally understand the entire ZIP File structure/CRC checks. However if you have a recenct support package level (my 640 SP13 system has it), there is a class called CL_ABAP_ZIP. Method LOAD is based upon the standards from pkware and has all the functionality you will need to extract the individual PDF files from your ZIP using only ABAP.\",\"author\":\"username\":\"thomas.jung\",\"displayName\":\"Thomas Jung\",\"groupIcons\":[\"name\":\"developer-advocate\",\"title\":\"This user is an SAP Developer Advocate\",\"priority\":12,\"name\":\"employee\",\"title\":\"This user is an SAP Employee\",\"priority\":21],\"suspended\":false,\"isCurrentUser\":false,\"parentAuthor\":\"username\":\"durairaj.athavanraja\",\"displayName\":\"Durairaj Athavan Raja\",\"groupIcons\":[\"name\":\"mentor-alumni\",\"title\":\"This user is an SAP Mentor Alumnus\",\"priority\":17],\"suspended\":false,\"isCurrentUser\":false,\"id\":1121148,\"creationDate\":1134588968000,\"activeRevisionId\":3632664,\"lastActivity\":1134588968000,\"parentId\":1118225,\"originalParentId\":1118192,\"likeCount\":1,\"visibility\":\"full\",\"depth\":0,\"attachments\":[],\"canVoteUpOrCancel\":false,\"relations\":\"canReport\":false,\"visibility\":\"full\",\"canEdit\":false,\"canUseDelete\":false,\"isLiked\":false,\"type\":\"comment\",\"canVoteUpOrCancel\":false,\"canConvertToAnswer\":false,\"canBeModerated\":false,\"canViewRevisions\":false,\"score\":1,\"showInReply\":false,\"reported\":false,\"canCancelReport\":false,\"canDelete\":false,\"canVoteDownOrCancel\":false,\"canComment\":false,\"canViewReports\":false,\"isCurrentUserAuthor\":false,\"liked\":false,\"moderatorComment\":false}]},\"1118254\":\"rootParentId\":1118254,\"commentsCount\":2,\"comments\":[\"body\":\"Hi Mickey,\\n\\nmy sample comes late:\\n\\n*open (normal oder komprimiert)\\n IF in_file CS '.Z' .\\n OPEN DATASET in_file FOR INPUT IN TEXT MODE FILTER 'uncompress'.\\n ELSE.\\n OPEN DATASET in_file FOR INPUT IN TEXT MODE.\\n ENDIF.\\n \\n DO.\\n READ DATASET in_file INTO bstring.\\n...\\n\\nhope it helps\\n\\nAndreas\",\"author\":\"username\":\"andreas.mann3\",\"displayName\":\"Andreas Mann\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"parentAuthor\":\"username\":\"micky.oestreich\",\"displayName\":\"Micky Oestreich\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"id\":1120083,\"creationDate\":1134555466000,\"activeRevisionId\":3631809,\"lastActivity\":1134555466000,\"parentId\":1118752,\"originalParentId\":1118192,\"likeCount\":0,\"visibility\":\"full\",\"depth\":0,\"attachments\":[],\"canVoteUpOrCancel\":false,\"relations\":\"canReport\":false,\"visibility\":\"full\",\"canEdit\":false,\"canUseDelete\":false,\"isLiked\":false,\"type\":\"comment\",\"canVoteUpOrCancel\":false,\"canConvertToAnswer\":false,\"canBeModerated\":false,\"canViewRevisions\":false,\"showInReply\":false,\"reported\":false,\"canCancelReport\":false,\"canDelete\":false,\"canVoteDownOrCancel\":false,\"canComment\":false,\"canViewReports\":false,\"isCurrentUserAuthor\":false,\"liked\":false,\"moderatorComment\":false]}"); const simplifiedQuestionView = JSON.parse("true"); (function() window.pageContext = mergeDeep(pageContext, question: id: 1118192, plug: "unzip-file-from-abap", votes: 0, questionTitle: "UNZIP file from ABAP", isClosed: false, isLocked: false, isRedirected: false, redirectedFromTitle: "", redirectedFromId: "", closedStatusData: JSON.parse(""), userVoted: false, relations: JSON.parse("\"canClose\":false,\"canUnredirect\":false,\"canReport\":false,\"visibility\":\"full\",\"canEdit\":false,\"canUseDelete\":false,\"canReopen\":false,\"type\":\"question\",\"canVoteUpOrCancel\":false,\"canViewRevisions\":true,\"canUnlock\":false,\"reported\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canCancelReport\":false,\"canComment\":true,\"isCurrentUserAuthor\":false,\"canViewReports\":false"), isQuestionAccepted: false , childToViewInfo: id: "" , comments: JSON.parse("\"1118225\":\"rootParentId\":1118225,\"commentsCount\":6,\"comments\":[\"body\":\">CL_ABAP_GZIP CL_ABAP_GZIP won't work because it only does compression/decompression. It doesn't acutally understand the entire ZIP File structure/CRC checks. However if you have a recenct support package level (my 640 SP13 system has it), there is a class called CL_ABAP_ZIP. Method LOAD is based upon the standards from pkware and has all the functionality you will need to extract the individual PDF files from your ZIP using only ABAP.\",\"author\":\"username\":\"thomas.jung\",\"displayName\":\"Thomas Jung\",\"groupIcons\":[\"name\":\"developer-advocate\",\"title\":\"This user is an SAP Developer Advocate\",\"priority\":12,\"name\":\"employee\",\"title\":\"This user is an SAP Employee\",\"priority\":21],\"suspended\":false,\"isCurrentUser\":false,\"parentAuthor\":\"username\":\"durairaj.athavanraja\",\"displayName\":\"Durairaj Athavan Raja\",\"groupIcons\":[\"name\":\"mentor-alumni\",\"title\":\"This user is an SAP Mentor Alumnus\",\"priority\":17],\"suspended\":false,\"isCurrentUser\":false,\"id\":1121148,\"creationDate\":1134588968000,\"activeRevisionId\":3632664,\"lastActivity\":1134588968000,\"parentId\":1118225,\"originalParentId\":1118192,\"likeCount\":1,\"visibility\":\"full\",\"depth\":0,\"attachments\":[],\"canVoteUpOrCancel\":false,\"relations\":\"canReport\":false,\"visibility\":\"full\",\"canEdit\":false,\"canUseDelete\":false,\"isLiked\":false,\"type\":\"comment\",\"canVoteUpOrCancel\":false,\"canConvertToAnswer\":false,\"canBeModerated\":false,\"canViewRevisions\":false,\"score\":1,\"showInReply\":false,\"reported\":false,\"canCancelReport\":false,\"canDelete\":false,\"canVoteDownOrCancel\":false,\"canComment\":false,\"canViewReports\":false,\"isCurrentUserAuthor\":false,\"liked\":false,\"moderatorComment\":false],\"1118254\":\"rootParentId\":1118254,\"commentsCount\":2,\"comments\":[\"body\":\"Hi Mickey,\\n\\nmy sample comes late:\\n\\n*open (normal oder komprimiert)\\n IF in_file CS '.Z' .\\n OPEN DATASET in_file FOR INPUT IN TEXT MODE FILTER 'uncompress'.\\n ELSE.\\n OPEN DATASET in_file FOR INPUT IN TEXT MODE.\\n ENDIF.\\n \\n DO.\\n READ DATASET in_file INTO bstring.\\n...\\n\\nhope it helps\\n\\nAndreas\",\"author\":\"username\":\"andreas.mann3\",\"displayName\":\"Andreas Mann\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"parentAuthor\":\"username\":\"micky.oestreich\",\"displayName\":\"Micky Oestreich\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"id\":1120083,\"creationDate\":1134555466000,\"activeRevisionId\":3631809,\"lastActivity\":1134555466000,\"parentId\":1118752,\"originalParentId\":1118192,\"likeCount\":0,\"visibility\":\"full\",\"depth\":0,\"attachments\":[],\"canVoteUpOrCancel\":false,\"relations\":\"canReport\":false,\"visibility\":\"full\",\"canEdit\":false,\"canUseDelete\":false,\"isLiked\":false,\"type\":\"comment\",\"canVoteUpOrCancel\":false,\"canConvertToAnswer\":false,\"canBeModerated\":false,\"canViewRevisions\":false,\"showInReply\":false,\"reported\":false,\"canCancelReport\":false,\"canDelete\":false,\"canVoteDownOrCancel\":false,\"canComment\":false,\"canViewReports\":false,\"isCurrentUserAuthor\":false,\"liked\":false,\"moderatorComment\":false]"), answerPager: answersCount: 3, page: 1, pageSize: 10, pageCount: 1, sort: "votes" , answers: JSON.parse("[\"body\":\"check out this threadtry CL_ABAP_GZIP class.RegardsRajaMessage was edited by: Durairaj Athavan Raja\",\"author\":\"username\":\"durairaj.athavanraja\",\"displayName\":\"Durairaj Athavan Raja\",\"groupIcons\":[\"name\":\"mentor-alumni\",\"title\":\"This user is an SAP Mentor Alumnus\",\"priority\":17],\"suspended\":false,\"isCurrentUser\":false,\"id\":1118225,\"posted\":1134472618000,\"votes\":2,\"isAccepted\":false,\"isLocked\":false,\"userVoted\":\"\",\"relations\":\"score\":2,\"canCancelAccept\":false,\"canUnlock\":false,\"canUseDelete\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canAccept\":false,\"type\":\"answer\",\"canVoteUpOrCancel\":false,\"isCurrentUserAuthor\":false,\"attachments\":[],\"body\":\"REPORT ZTESTUNIX line-size 400\\n no standard page heading.\\n\\nselection-screen begin of block ucmd with frame title text-001.\\nparameters: unixcom like rlgrap-filename. " ...SAP Interface file\\nselection-screen end of block ucmd.\\n\\ndata: begin of tabl occurs 500,\\n line(400),\\n end of tabl.\\n\\ndata: lines type i.\\n\\n\\n*----------------------------------------------------------------------\\n\\nstart-of-selection.\\n refresh tabl.\\n\\n call 'SYSTEM' id 'COMMAND' field unixcom\\n id 'TAB' field tabl[].\\n\\n describe table tabl lines lines.\\n loop at tabl.\\n write:/01 tabl-line.\\n endloop.\\n skip 2.\\n if lines = 0.\\n write:/ 'NO Occurances were found'.\\n else.\\n write:/ 'Command was successfully executed' color col_total.\\n write:/ 'Number of entries in Search' color col_total,\\n lines color 6.\\n endif.\\n*----------------------------------------------------------------------\\n\\nend-of-selection.\\n*----------------------------------------------------------------------\\n\\nwhile running give the command as\\nunzip test.zip -x dir\\nthen it will unzip test.zip file to dir called dir.\\nyou can specify the filepath instead of file...\\n\\nregards\\nvijay\",\"author\":\"username\":\"vijaybabu.dudla\",\"displayName\":\"Vijay Dudla\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"id\":1118240,\"posted\":1134473216000,\"votes\":0,\"isAccepted\":false,\"isLocked\":false,\"userVoted\":\"\",\"relations\":\"canCancelAccept\":false,\"canUnlock\":false,\"canUseDelete\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canAccept\":false,\"type\":\"answer\",\"canVoteUpOrCancel\":false,\"isCurrentUserAuthor\":false,\"attachments\":[],\"body\":\"Hi Mickey,this is more effective !for unix-systems you can say:OPEN DATASET file FOR input FILTER 'uncompress'.-> so you need not to unzip your fileregards Andreas\",\"author\":\"username\":\"andreas.mann3\",\"displayName\":\"Andreas Mann\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"id\":1118254,\"posted\":1134473800000,\"votes\":0,\"isAccepted\":false,\"isLocked\":false,\"userVoted\":\"\",\"relations\":\"canCancelAccept\":false,\"canUnlock\":false,\"canUseDelete\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canAccept\":false,\"type\":\"answer\",\"canVoteUpOrCancel\":false,\"isCurrentUserAuthor\":false,\"attachments\":[]]"), answerForm: formAction: "/answers/1118192/post.json", textareaName: "body", textareaErrors: "", isAttachmentsEnabled: true, answerEditorialGuideline: title: "Before answering", content: "You should only submit an answer when you are proposing a solution to the poster\'s problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that your answer complies with our Rules of Engagement.", links: [ title: "Rules of Engagement", href: " -of-engagement.html", ] , answerMinBodyLength: '10', answerMaxBodyLength: '20000' , currentUser: sapInternalId: '', permissions: canVoteUpOrCancel: false, canVoteDownOrCancel: false, canModerate: false, , isVotedUp: false, isVotedDown: false , alerts: alertModeratorMinLength : "It should be given a proper explanation about why the content is inappropriate.", alertModeratorMinLengthValue : "10", alreadyReportedMessage : "You already have an active moderator alert for this content." , url: profileApiBaseUrl: ' -api.services.sap.com', followUnfollowQuestion: '/sap/nodeSubscription.json', isFollowingQuestion: '/sap/isFollowingNode.json', vote: voteUp: '/commands/0/voteup.json', voteDown: '/commands/0/votedown.json', cancelVote: '/commands/0/cancelvote.json' , rss: answers: '/feed/1118192/answers.rss', answersAndComments: '/feed/1118192/comments-and-answers.rss' , authorizeUploadContext: type: 'answer' , atMention: userSearchServiceUrl: ' ', currentUserName: '', useNewUSSCORS: true, atMentionDelayMs: 100, showMentionInRedactor: true , attachmentSettings: commentMaxAttachments: '2', answerMaxAttachments: '10', commentMaxAttachmentSizeBytes: '1048576', answerMaxAttachmentSizeBytes: '1048576', commentAttachmentsSizeBytesTotal: '2097152', answerAttachmentsSizeBytesTotal: '10485760' , editor: editorClipboardUploadEnabled: true ) )(); Home

  • Community

  • Ask a Question

  • Write a Blog Post

Login / Sign-up Search Questions and Answers 0 Micky Oestreich Dec 13, 2005 at 11:02 AM UNZIP file from ABAP 3275 Views Follow RSS Feed Hi, 2ff7e9595c


0 views0 comments

Recent Posts

See All

Comments


bottom of page