Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
TAR
TAR (for "Tape ARchive"). TAR can be used to make a big file filled with many smaller files. It can be
easily transported across directories, mahcines or networks. Need to use the TAR command to extract files from an archive or to create an archive (also known as tarball). A single file that contains various individual files is called tarball or an archive. A ".tar" file is not a compressed files , it is a collection of files within a single file uncompressed. If the file is a .tar.gz ("tarball") or ".tgz" file , it is a collection of files that is compressed. .tar.gz is same thing as tar.gz. Familiar Options in tar Command. c, x, v, f, z These are commonly used tar options. c = Create a new tar file. x = Extract the contents (.tar file) from a archive. v = Verbose output , showing progress to compress or uncompress. f = Create the tar file with filename provided as the argument. z = Use gzip to zip it (compress or decompress automatically).
POINTS TO NOTE :
TAR creates one tar file out of several files and directories. .tgz extension is a shorthand version for the .tar.gz extension. Important to know , TAR doesnt compress the files and (or) directories. TAR file will take up the same amount of space as all the individual files. A TAR file can be compressed by using gzip (-z) or bzip2(-j). Successful People in life seem to like LINUX
Page 1 of 8
Lets check all files in directory # ls -l -rw-r--r-- 1 root root 74471 Jan 18 09:45 f1 -rw-r--r-- 1 root root 102019 Jan 18 09:45 f2 -rw-r--r-- 1 root root 10737 Jan 18 09:45 f3 -rw-r--r-- 1 root root 47199 Jan 18 09:45 f4 Creating Simple tar file using multiple files # tar -cf backup.tar f1 f2 f3 f4 # ls -l -rw-r--r-- 1 root root 245760 Jan 18 10:31 backup.tar -rw-r--r-- 1 root root 74471 Jan 18 09:45 f1 -rw-r--r-- 1 root root 102019 Jan 18 09:45 f2 -rw-r--r-- 1 root root 10737 Jan 18 09:45 f3 -rw-r--r-- 1 root root 47199 Jan 18 09:45 f4 Successful People in life seem to like LINUX
Page 2 of 8
Page 3 of 8
tar.gz is a compressed tar archive. The .gz file extension are created using Gzip program which reduces the size of the tar files. gunzip/gzip is software application used for file compression and decompression. gzip is short for GNU zip ; the program is a free software replacement for the compress program used in early UNIX/LINUX systems. The best option for decompress .tgz / tar.gz files. $ tar -zxvf filename.tgz or $ ta r -zxvf filename.tar.gz Examples for (Zip/Compress) and (Unzip/Uncompress) a tar file $ tar -xvf example.tar Extract the contents of example.tar and display the files as they are extracted. $ tar -cf backup.tar /home/rose/test_dir Create a TAR file named backup.tar from the contents of /home/rose/test_dir $ tar -zxvf example.tgz Gunzip (uncompress) example.tgz and then extract the contents. $ tar -tvf example.tar List contents of example.tar to the screen. Successful People in life seem to like LINUX
Page 4 of 8
Page 8 of 8