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.


Compress files into tar file


entrynames = tar(...)


tar(tarfilename,files) creates a tar file named tarfilename from the list of files and folders specified in files. Folders recursively include all of their content. If files includes relative paths, the tar file also contains relative paths. The tar file does not include absolute paths.

tar(tarfilename,files,rootfolder) specifies the path for files relative to rootfolder rather than the current folder. Relative paths in the tar file reflect the relative paths in files, and do not include path information from rootfolder.

entrynames = tar(...) returns a cell array of character vectors containing the names of the files in tarfilename. If files includes relative paths, entrynames also contains relative paths.

Input Arguments


Name of the tar file, specified as a character vector. If tarfilename has no extension, MATLAB® appends the .tar extension. The tarfilename extension can end in .tgz or .gz. In this case, tarfilename is gzipped.


List of files or folders included in tarfilename, specified as a character vector or a cell array of character vectors.

Individual files that are on the MATLAB path can be specified as partial path names. Otherwise an individual file can be specified relative to the current folder or with an absolute path.

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


Path for files, specified as a character vector.


Tar all files in the current folder to the file backup.tgz.



tar cannot compress folders larger than 2 GB.

See Also

| | | |

Introduced before R2006a

Was this topic helpful?