Linux - tar
tar -C dirname > archive.tar
gzip archive.tar
tar -xvzf filename.tar.gz
gzip -d -C ../rsaref20.tar.Z | tar -xvf
tar -cf archive.tar dirname
How can we create a tar archive of a folder?
tar -zcvf archiveName.tar.gz directoryName
How can we unarchive an archive?
tar -zxvf archiveName.tar.gz
What are the command line options (or keys) for the tar command?
tar [key] files
- r: named files are written at the end
- x: named files are extracted from tape
- t: named files are listed if they are on tap
- u: files are added to tape if not already there or newer since last archived
- c: create an archive
- w: interactive
- f: use the sub-options <pathname> as the archive
- -I: filter the output through bzip2
- -k: keep existing files. Do not override them from the archive
- -p: preserve permissions
- -P: do not strip leading '/' from filenames
- -s: preserve order. List of names to extract is sorted to match the archive
- --preserve: like -p -s
- --same-owner: create the extracted files with the same ownership
- -T F: get the names to extract from a file F
- -W: verify. Attempt to verify the archive after writing it.
- --exclude files: exclude files from the resulting archive
- -Z: filter the archive through compress to produce a file ending with .Z
- -z: filter through gzip
tar -c /dev/tape/usros /usr/os
tar -cf /dev/floppy /usr
tar -cfv /dev/floppy /home /etc/passwd /etc/group
tar -cf archive.tar dirname; gzip archive.tar
cd /chem1
tar -cf - -c /chem olddir | tar -xvpf -
The -C option of the first tar command set the current directory for the first tar command. The - argument for the -f option specifies that the output to standard output. The first tar command creates an archive of /chem/olddir and write it to standard output. The second tar command extract files from standard input ( specified by the - ) and write its current directory which is /chem1. The -p option for the second tar command tells it to preserve ownership.
tar -c /dev/tape filenames // create an arhive on a tape device
tar -cf archiveName.tar filenames // create an archive using normal file
tar -rf archiveName.tar filenames // append files to archive
tar -uf archiveName.tar filenames // only update files that are new.
tar -tf archiveName.tar filenames // list given files in given archive
// omit the filenames argument to list all files in the arhive
tar -xf archiveName.tar filenames // extract only the given files from the archive
page revision: 4, last edited: 20 May 2017 00:38