Excluding files or folders with tar is straightforward once you know the --exclude option.

Assume a directory tree like this:

1
2
3
4
5
/home/cliper/
└── folder/
    ├── file1
    ├── file2
    └── folder/

If you want to archive the directory but leave out file2 and the nested folder/, you can do:

1
2
3
4
tar -czpf filename.tgz \
  --exclude=/home/cliper/folder/file2 \
  --exclude=/home/cliper/folder/folder \
  /home/cliper/folder

That is a handy pattern when creating backups and you want to skip generated files, caches, or other directories you do not need in the archive.