tar Flashcards
tar
GNU tar is an archiving program designed to store multiple files in a single file (an archive), and to manipulate such archives.
tar -cvf file.tar /home/user
Creates a tar archive file.
c, Creates a new .tar archive file.
v, verbose
f, File name type of archive file.
tar -cvzf file.tar.gz /home/user
Creates a compressed gzip archive file with the z option.
tar -cvfj file.tar.bz2 /home/user
Creates a highly compressed bz2 archive file by using the j option.
tar -xvf file.tar
Extracts a tar file into the current directory.
x, Extracts the tar file.
v, verbose.
f, File type archive.
tar -xvf file.tar -C /home/user/documents
Extracts a tar file into specified directory by using the -C option.
tar -xvf file.tar.gz
or
tar -xvf file.tar.bz2
Decompresses and extracts a compressed tar file to current directory.
tar -tvf userfiles.tar
or
tar -tvf userfiles.tar.gz
or
tar -tvf userfiles.tar.bz2
This command lists the contents of userfiles.tar and userfiles.tar.gz by using the -t option.
tar -xvf userfiles.tar userscript.sh
or
tar –extract –file=userfiles.tar userscript.sh
These commands will extract a single file by calling it out from the .tar file.
tar -zxvf userfiles.tar.gz user.doc
or
tar -jxvf userfiles.tar.bz2 user.doc
These commands will extract user.doc out of userfiles.tar.gz and userfiles.tar.bz2 respectively. Make sure to add the right -z or -j flags depending on the mode of compression.
tar -xvf serverfile.tar “file1.php” “file2.html”
or
tar -zxvf serverfile.tar.gz “file1.php” “file2.html”
or
tar -jxvf serverfile.tar.bz2 “file1.php” “file2.html”
These commands will untar multiple files by using quotation marks around the files.
tar -xvf serverfiles.tar –wildcards ‘*.php’
or
tar -zxvf serverfiles.tar.gz –wildcards ‘*.php’
or
tar -jxvf serverfiles.tar.bz2 –wildcards ‘*.php’
These commands will extract multiple files from the tar files and compressed tar files by using the –wildcard option and then a wildcard search in single quotes.
tar -rvf serverfiles.tar xyz.conf
or
tar -rvf serverfiles.tar php/
These commands will add a file or directory to a tar archive by using the -r option.
-r, Appends a tar file.
tar -rvf MyImages-14-09-12.tar.gz xyz.txt
or
tar -rvf Phpfiles-org.tar.bz2 xyz.txt
These commands will add files to the gzip and bzip2 files.
tar -tvfW serverfiles.tar
This command will list and verify a .tar file by using -W.
-W, Verifies a .tar file.
Note: Verifications cannot be done on a .tar file compressed by gzip or bzip2.