This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the 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 string cell array of the names of the files contained in tarfilename. If files includes relative paths, entrynames also contains relative paths.

Input Arguments


String specifying the name of the tar file. 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.


String or cell array of strings containing the list of files or folders included in tarfilename.

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.


String specifying the path for files.


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


More About

collapse all


tar cannot compress folders larger than 2 GB.

See Also

| | | |

Introduced before R2006a

Was this topic helpful?