All commands tested on Mac OS Monterey / Sep 12, 2023

Tar Create Examples

How to create a tar archive of a directory

Create a tar archive called my-directory.tar of a directory my-directory/ in the current working directory.
View the command

How to create a tar archive of multiple directories

Create a tar archive called directories.tar of multiple directories directory-1/ and directory-2/ in the current working directory.
View the command

How to create a tar archive without the hidden files

Create a tar archive called my-directory.tar of a directory my-directory/ but without the hidden .* files.
View the command

How to create a tar archive of files by filetype

Create a tar archive called jpgs.tar of only JPEG image files in directory/ (at all directory levels).
View the command

How to create a tar archive of files by multiple filetypes

Create a tar archive called images.tar of image files in directory/ (at all directory levels).
View the command

How to create a tar archive excluding a directory

Create a tar archive called directory.tar of directory/ excluding the directory/backups/ directory.
View the command

How to create a tar archive excluding multiple directories

Create a tar archive called directory.tar of directory/ excluding the directory/backups and directory/dist directories.
View the command

How to create a tar archive excluding a specific filetype

Create a tar archive called my-directory.tar of a directory my-directory/ but excluding files of a specific filetype.
View the command

How to create a tar archive excluding files by multiple filetypes

Create a tar archive called my-directory.tar of a directory my-directory/ excluding files by multiple filetypes.
View the command

How to create a tar archive without the parent directory

Create a tar archive called my-directory.tar of my-directory/ without the parent directory.
View the command