All commands tested on Mac OS Monterey / Jul 02, 2024

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.

You can use this short tar command.

              
                  tar -cvf directories.tar directory-1/ directory-2/
              
          

Or this more verbose tar command.

              
                  tar --create --verbose --file directories.tar directory-1/ directory-2/
              
          

Options explained

  1. -c or --create tells tar to create a new archive
  2. v or --verbosetells tar to produce verbose output
  3. f or --filetells tar that the next parameter will be the tar file to create, extract, append to, list, etc.

More commands for creating tar archives