Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

tar

Compress files into tar file

Syntax

tar(tarfilename,filenames)
tar(tarfilename,filenames,rootfolder)
entrynames = tar(___)

Description

example

tar(tarfilename,filenames) compresses contents of filenames into the tar file tarfilename. tar recursively compresses the content in folders. The resulting tar file contains the paths of filenames relative to the current folder. The tar file does not store absolute paths.

example

tar(tarfilename,filenames,rootfolder) specifies the paths for filenames relative to rootfolder rather than the current folder.

example

entrynames = tar(___) returns a cell array of character vectors containing the names of the files included in tarfilename. You can use this syntax with any of the input argument combinations in the previous syntaxes.

Examples

collapse all

Compress all files with a .m and .mlx extension in the current folder to the file backup.tar.

tarfiles = tar('backup.tar',{'*.m','*.mlx'})
tarfiles = 1x1 cell array
    {'CompressFilesToTarExample.mlx'}

Create a tar file of a folder including all subfolders, and store the relative paths in the file.

Create a folder myfolder containing a subfolder mysubfolder and the files membrane.m and logo.m.

mkdir myfolder;
movefile('membrane.m','myfolder');
movefile('logo.m','myfolder');
cd myfolder;
mkdir mysubfolder;
cd ..

Create a tar file of the contents of myfolder, including all subfolders.

tarfiles = tar('myfiles.tar','myfolder');

Input Arguments

collapse all

Name of tar file to create, specified as a character vector. If tarfilename has no extension, MATLAB® appends the .tar extension. If you specify a .tgz or .gz extension, tar compresses the specified files using gzip.

tarfilename must include a path relative to the current folder or an absolute path.

Names of files or folders to compress, specified as a character vector or a cell array of character vectors. filenames must be smaller than 2 GB.

Files that are on the MATLAB path can include a partial path. Otherwise, files must include a path relative to the current folder or an absolute path.

Folders must include a path relative to the current folder or an absolute path. On UNIX® systems, folders also can start with ~/ or ~username/, which expands to the current user's home folder or the specified user's home folder, respectively. You can use the wildcard character * when specifying files or folders, except when relying on the MATLAB path to resolve a file name or partial path name.

Root paths for the files to compress, specified as a character vector.

See Also

| | | |

Introduced before R2006a

Was this topic helpful?