Documentation Center

  • Trial Software
  • Product Updates

untar

Extract contents of tar file

Syntax

untar(tarfilename)
untar(tarfilename,outputdir)
untar(url,___)
filenames = untar(___)

Description

untar(tarfilename) extracts the archived contents of tarfilename into the current directory and sets the files' attributes. It overwrites any existing files with the same names as those in the archive if the existing files' attributes and ownerships permit it. For example, if you rerun untar on the same tarfilename, MATLAB® software does not overwrite files with a read-only attribute; instead, untar displays a warning for such files. On Microsoft® Windows® platforms, the hidden, system, and archive attributes are not set.

tarfilename is a string specifying the name of the tar file. tarfilename is gunzipped to a temporary directory and deleted if its extension ends in .tgz or .gz. If an extension is omitted, untar searches for tarfilename appended with .tgz, .tar.gz, or .tar. tarfilename can include the directory name; otherwise, the file must be in the current directory or in a directory on the MATLAB path.

untar(tarfilename,outputdir) uncompresses the archive tarfilename into the directory outputdir. If outputdir does not exist, MATLAB creates it.

untar(url,___) extracts the tar archive from an Internet URL. The URL must include the protocol type (for example, 'http://' or 'ftp://'). MATLAB downloads the URL to a temporary directory, and then deletes it.

filenames = untar(___) extracts the tar archive and returns the names of the extracted files in the string cell array filenames. If outputdir specifies a relative path, filenames contains the relative path. If outputdir specifies an absolute path, filenames contains the absolute path.

Examples

Using tar and untar to Copy Files

Copy all .m files in the current directory to the directory backup.

tar('mymfiles.tar.gz','*.m');
untar('mymfiles','backup');

Using untar with URL

Run untar to list Cleve Moler's "Numerical Computing with MATLAB" examples to the output directory ncm.

url ='http://www.mathworks.com/moler/ncm.tar.gz';
ncmFiles = untar(url,'ncm')

See Also

| | | |

Was this topic helpful?