Combines files to create an archive. It also extracts files from the archive.

BSDTAR(1) BSD General Commands Manual

     tar -- manipulate tape archives

     tar [bundled-flags <args>] [<file> | <pattern> ...].
     tar {-c} [options] [files | directories].
     tar {-r | -u} -f archive-file [options] [files | directories]
     tar {-t | -x} [options] [patterns]


  • The files in jupyter notebook format on github are here .


The author’s OS is macOS, and the options are different from Linux and Unix commands.

When you actually run the command, you will need to use the prefix ! and %%bash in the first line.

ProductName: Mac OS X
ProductVersion: 10.14.6
BuildVersion: 18G95
!bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.

Example usage

Create a file

echo "Preparing a file"
echo "1234567890" > temp1
echo "0987654321" > temp2

tar -czf temp.tgz temp1 temp2
echo -e "\n<ls>"
ls | grep temp
Prepare the file


Unzip the files

tar -xzf temp.tgz

Typical options

For many years, I have used the following two commands, which are a combination of four commands. v is used when necessary in verbose. I have never had any trouble with these two.

Decompressing files

  • xzvf

Create a file

  • czvf