提取(解压)
如果要将归档文件提取到指定的目录,则会在下面运行命令:
tar -xf confidential.tar.gz -C /home/students/files
如果我们只想将Companical.tar.gz文件提取到我们正在处理的同一个目录中,则我们运行以下命令:
tar -xf confidential.tar.gz
查看tar的帮助文档:
Usage: tar [OPTION. ] [FILE]. GNU 'tar' saves many files together into a single tape or disk archive, and can restore individual files from the archive. Examples: tar -cf archive.tar foo bar # Create archive.tar from files foo and bar. tar -tvf archive.tar # List all files in archive.tar verbosely. tar -xf archive.tar # Extract all files from archive.tar. Local file name selection: --add-file=FILE add given FILE to the archive (useful if its name starts with a dash) -C, --directory=DIR change to directory DIR --exclude=PATTERN exclude files, given as a PATTERN --exclude-backups exclude backup and lock files --exclude-caches exclude contents of directories containing CACHEDIR.TAG, except for the tag file itself --exclude-caches-all exclude directories containing CACHEDIR.TAG --exclude-caches-under exclude everything under directories containing CACHEDIR.TAG --recursion recurse into directories (default) -T, --files-from=FILE get names to extract or create from FILE --unquote unquote input file or member names (default) --verbatim-files-from -T reads file names verbatim (no option handling) -X, --exclude-from=FILE exclude patterns listed in FILE File name matching options (affect both exclude and include patterns): --anchored patterns match file name start --ignore-case ignore case --no-anchored patterns match after any '/' (default for exclusion) --no-ignore-case case sensitive matching (default) --no-wildcards verbatim string matching --no-wildcards-match-slash wildcards do not match '/' --wildcards use wildcards (default for exclusion) --wildcards-match-slash wildcards match '/' (default for exclusion) Main operation mode: -A, --catenate, --concatenate append tar files to an archive -c, --create create a new archive -d, --diff, --compare find differences between archive and file system --delete delete from the archive (not on mag tapes!) -r, --append append files to the end of an archive -t, --list list the contents of an archive --test-label test the archive volume label and exit -u, --update only append files newer than copy in archive -x, --extract, --get extract files from an archive Operation modifiers: --check-device check device numbers when creating incremental archives (default) -g, --listed-incremental=FILE handle new GNU-format incremental backup -G, --incremental handle old GNU-format incremental backup --hole-detection=TYPE technique to detect holes --ignore-failed-read do not exit with nonzero on unreadable files --level=NUMBER dump level for created listed-incremental archive -n, --seek archive is seekable --no-check-device do not check device numbers when creating incremental archives --no-seek archive is not seekable --occurrence[=NUMBER] process only the NUMBERth occurrence of each file in the archive; this option is valid only in conjunction with one of the subcommands --delete, --diff, --extract or --list and when a list of files is given either on the command line or via the -T option; NUMBER defaults to 1 --sparse-version=MAJOR[.MINOR] set version of the sparse format to use (implies --sparse) -S, --sparse handle sparse files efficiently Overwrite control: -k, --keep-old-files don't replace existing files when extracting, treat them as errors --keep-directory-symlink preserve existing symlinks to directories when extracting --keep-newer-files don't replace existing files that are newer than their archive copies --no-overwrite-dir preserve metadata of existing directories --one-top-level[=DIR] create a subdirectory to avoid having loose files extracted --overwrite overwrite existing files when extracting --overwrite-dir overwrite metadata of existing directories when extracting (default) --recursive-unlink empty hierarchies prior to extracting directory --remove-files remove files after adding them to the archive --skip-old-files don't replace existing files when extracting, silently skip over them -U, --unlink-first remove each file prior to extracting over it -W, --verify attempt to verify the archive after writing it Select output stream: --ignore-command-error ignore exit codes of children --no-ignore-command-error treat non-zero exit codes of children as error -O, --to-stdout extract files to standard output --to-command=COMMAND pipe extracted files to another program Handling of file attributes: --atime-preserve[=METHOD] preserve access times on dumped files, either by restoring the times after reading (METHOD='replace'; default) or by not setting the times in the first place (METHOD='system') --clamp-mtime only set time when the file is more recent than what was given with --mtime --delay-directory-restore delay setting modification times and permissions of extracted directories until the end of extraction --group=NAME force NAME as group for added files --group-map=FILE use FILE to map file owner GIDs and names --mode=CHANGES force (symbolic) mode CHANGES for added files --mtime=DATE-OR-FILE set mtime for added files from DATE-OR-FILE -m, --touch don't extract file modified time --no-delay-directory-restore cancel the effect of --delay-directory-restore option --no-same-owner extract files as yourself (default for ordinary users) --no-same-permissions apply the user's umask when extracting permissions from the archive (default for ordinary users) --numeric-owner always use numbers for user/group names --owner=NAME force NAME as owner for added files --owner-map=FILE use FILE to map file owner UIDs and names -p, --preserve-permissions, --same-permissions extract information about file permissions (default for superuser) --same-owner try extracting files with the same ownership as exists in the archive (default for superuser) -s, --preserve-order, --same-order member arguments are listed in the same order as the files in the archive --sort=ORDER directory sorting order: none (default), name or
tar命令
语法
tar [OPTION. ] [FILE].
选项
FILES. | tar命令归档的文件 |
---|---|
-c, -create | 使用-c或者-create创建一个新的存档 |
-f, -file | 使用-f或者-file创建文件存档 |
-x, -extract | 使用-x或者-extract从存档中提取文件 |
-t, -list | 使用-t或者-list在归档文件中显示或者列出文件 |
-u, -update | 使用-u或者-update仅在现有存档中的副本中只添加文件 |
-j, -bzip2 | 使用-j或者-bzip2通过bzip2创建新存档 |
-z, -gzip, -gunzip | 使用-z或者-gzip选项通过tar.gz创建新存档 |
-C, -directory=DIR | 使用-c或者-directory使用指定的目录创建新存档 |
-v, -verbose | 使用-v或者-verbose选项输出每个已处理的每个目录的诊断 |
-help | 使用-help选项显示此帮助和退出 |
-version | 使用-version选项输出版本信息并退出 |
归档
创建private secrets两个文件的归档文件,生成的文件名称为confidential.tar
tar -cf confidential.tar private secrets
使用选项-C指定要归档的目录
tar -czf confidential.tar.gz -C /documents/public/students
日期:2020-07-07 20:55:42 来源:oir作者:oir