Ubuntu Tutorial

Tar File : tar command is used to create(compressed tar file) and extract tar files.

syntax : tar option tar-file-name files/directories

in following example we create first.tar file from scss and src directory.

create tar file

following table shows options for tar command.

Option Description
-c or --create create new archive.
-t or --list print the content in archive
-u or --update Append files which are newer than the corresponding copy in the archive
-v or --verbose print verbose information
-A or --catenate or --concatenate append archive to the end of another archive
-z create tar file using gzip
-x or --extract or --get extract files from an archive
-W or --verify verify the archive after writing it
-r or --append append files to the end of an archive

following are examples for tar command.

Command Description
tar -cvf first.tar dir1 dir2 create uncompressed tar archive (first.tar) /file containing dir1 and dir2
tar -tvf first.tar print all content of uncompressed tar archive (first.tar) /file on terminal
tar -tvf first.tar dir1 print content of dir1 directory from uncompressed tar archive (first.tar) /file on terminal
tar -tvf first.tar --wildcards "dir1/*.css" print all css file present in dir1 directory from uncompressed tar archive (first.tar) /file on terminal Note : The --wildcards(*) option tells tar to interpret wildcards in the name of the files
tar -tvf first.tar --totals print size(after extraction) of files
tar -xvf first.tar extract all files from archive(first.tar). you will see extracted dir1 and dir2 in directory
tar -uvf first.tar a.txt dir3 or tar -rvf first.tar a.txt dir3 update(-u) uncompressed tar archive (first.tar) /file by adding a.txt and dir3 Note : we can not update compressed tar file.
tar -xvf first.tar dir1 dir2 extract given files or directories from archive(first.tar).in our case dir1 and dir2 will be extracted.
tar -cvzf second.tar.gz dir1 dir2 a.txt create gzip(-z) compression of tar archive/file
tar -xvzf second.tar.gz extracting a gzip tar archive/file (second.tar.gz)
tar -xvzf second.tar.gz dir2 a.txt extracting dir2 and a.txt from gzip tar archive/file (second.tar.gz).

Zip File : zip command is used to create zip file.

syntax : zip option zip-file-name files/directories

in following example we create first.zip file from src and vendor directory.

create zip file

following are examples for zip command.

Command Description
zip first.zip file1.txt create zip file containing file1.txt
zip -r first.zip dir1 dir2 a.txt create zip file containing directories(dir1 and dir2) and files(a.txt)
unzip first.zip extract all content of zip file
zip -d first.zip file1.txt delete file1.txt from first.zip
less first.zip print properties of zip file like name, date, time, size etc