tldr/pages/common/tar.md

42 lines
1.1 KiB
Markdown
Raw Normal View History

2013-12-08 08:56:16 +00:00
# tar
> Archiving utility.
> Often combined with a compression method, such as gzip or bzip.
> More information: <https://www.gnu.org/software/tar>.
2013-12-08 08:56:16 +00:00
- Create an archive from files:
2013-12-08 08:56:16 +00:00
2019-10-20 00:07:10 +01:00
`tar cf {{target.tar}} {{file1}} {{file2}} {{file3}}`
2013-12-08 08:56:16 +00:00
- Create a gzipped archive:
2013-12-08 08:56:16 +00:00
2019-10-20 00:07:10 +01:00
`tar czf {{target.tar.gz}} {{file1}} {{file2}} {{file3}}`
2013-12-08 08:56:16 +00:00
- Create a gzipped archive from a directory using relative paths:
`tar czf {{target.tar.gz}} -C {{path/to/directory}} .`
- Extract a (compressed) archive into the current directory:
2013-12-08 08:56:16 +00:00
`tar xf {{source.tar[.gz|.bz2|.xz]}}`
2020-07-28 15:27:36 +01:00
- Extract a (compressed) archive into the target directory:
2020-07-28 15:27:36 +01:00
`tar xf {{source.tar[.gz|.bz2|.xz]}} -C {{directory}}`
- Create a compressed archive, using archive suffix to determine the compression program:
2019-10-20 00:07:10 +01:00
`tar caf {{target.tar.xz}} {{file1}} {{file2}} {{file3}}`
- List the contents of a tar file:
`tar tvf {{source.tar}}`
- Extract files matching a pattern:
`tar xf {{source.tar}} --wildcards "{{*.html}}"`
- Extract a specific file without preserving the folder structure:
`tar xf {{source.tar}} {{source.tar/path/to/extract}} --strip-components={{depth_to_strip}}`