Main Content

tar

Compress files into tar file

Description

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.

example

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 or a string scalar. 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.

Data Types: char | string

Names of files or folders to compress, specified as a character vector, a cell array of character vectors, or a string array.

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.

Data Types: char | string

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

Data Types: char | string

Output Arguments

collapse all

Names of compressed files, returned as a cell array of character vectors. Each element in entrynames is the path of an entry relative to the archive.

Version History

Introduced before R2006a

expand all

See Also

| | | |