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

How to create a tar archive excluding a directory

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

You can use this short tar command.

              
                  tar --exclude directory/backups/ -cvf directory.tar directory/
              
          

Or this more verbose tar command.

              
                  tar --exclude directory/backups/ --create --verbose --file directory.tar directory/
              
          

Load WordPress Sites in as fast as 37ms!

Options explained

  1. --exclude tells tar not to process files or directories that match the specified pattern
  2. -c or --create tells tar to create a new archive
  3. v or --verbosetells tar to produce verbose output
  4. 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