tar (copy files into or restore files from an archive file)
Tar is a utility used to create an archive file, called a tarball. Files can be added to the archive file or removed from the archive file using tar. The action of tar depends on the options used. Format: tar options tarfile filelist
Examples: tar -cf newarch.tar *
tar -xf oldarch
The first example creates a new archive file called newarch and stores all the files in the current directory in the new archive. It's customary to name the file with a .tar extension. The second example extracts all the files in the archive oldarch. After extraction, the files are in the current directory and the archive is still there also. Tar has two types of options. One option from the function options is required, determining the action tar performs. The second table lists normal options, totally optional. Required options | What It Does | Examples |
---|
-A | Add another archive to the end of the current archive | tar -Af oldarch newarch.tar | -c | Create a new archive | tar -cf newarch.tar * | -d | Compare archived files with source files and report differences | tar -df tararch.tar | -delete | Remove file from archive file | tar -df tararch.tar file26.txt | -r | Append files to end of archive file | tar -rf tararch.tar rep* | -t | Display names of files in archive | tar -tf tararch.tar | -u | Add files if not already in archive or if they have been modified | tar -uf tararch.tar rep* | -x | Extract files from the archive | tar -xf projarch.tar | Opt | What It Does | Examples |
---|
-f file | Use specified archive file. | tar -xf projarch.tar | -j | Compress files with bzip2 before storing in archive file | tar -cjf arc.tar * | -k | Do not overwrite existing files with extracted files | tar -xkf projarc.tar | -m | Do not keep modification time with extracted files. Set modification time to the time the file was extracted. | tar -xmf proj.tar | -p | Keep the permission of the extracted files | tar -xpf proj.tar | -z | Compress files with Gzip before storing in archive file |
tar -czf newproj.tar
proj1*
| |