«

»

Mar 18

Command line zip, unzip, and tar

In maintaining linux systems I often find that I need to zip the contents of a folder or unzip some settings.  Zip is useful for compressing and transmitting files.  There isn’t anything new here and it is straight out of the man pages but since I only use it once every 6 months I’m going to summarize it here.

To zip a group of files in a directory, cd to that directory and with the command below you get stuff.zip in the same directory:

zip stuff *

 

If you want the hidden files in a directory add the . wildcard:

zip stuff .* *

 

That doesn’t get you any subdirectories to get that use:

zip -r stuff foo

 

That command will create a stuff.zip archive of the foo directory.

To unzip stuff.zip into the current directory and any subdirectories below it, creating subdirectories as necessary:

unzip stuff

 

unzip -tq stuff

 

Will test and print out if the Archive is OK.

 

Tar files like Newfile.tar.Z can gzip on creation or extraction. To unarchive a tar file use

tar -xvf Newfile.tar

 

or

tar -Zxvf Newfile.tar.Z  #Capitol Z is used for compress or
tar -zxvf Newfile.tar.zip  #for a gzip, gunzip file or
tar -jxvf Newfile.tar.bzip2  #for a bzip2 archive

 

where -z -Z -j or -a (auto-compress) will compress. -x = extract, -v = verbose, -t = file

tar -cf Newfile.tar foo bar

 

-c = create will create an archive of foo and bar files.  You can use * for the directory.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>