Answering my own question yesterday, I wrote a bash script which archives all directories within a defined directory into their own separate archive files. I have also defined a variable for a file which would include a list of directories I would like to skip. I wanted it to work something like the --exclude-from parameter for tar, but obviously that would not work. What is the best way I can accomplish this? I am thinking that grep would be the path I should take.#!/bin/bash#STARTTIME=`date +%Y-%m-%d_%Hh%Mm`     # Append date and time to backup fileSRCDIR=/srv                      # Location of directories to backupDESDIR=/srv/backup               # Destination of backup filesEXCLUDE=exclude.txt  # File which defines what to exclude from archivingfor dir in $SRCDIR/*/do  base=$(basename $dir)  tar -cpzf $DESDIR/$base-$TIME.tar.gz $dirdone#END
How to exclude directories from tar in this script?
linux;bash;tar;grep
You can use grep to check if the directory is listed in your exclude file, as shown in this answer on SO:#!/bin/bash#STARTTIME=`date +%Y-%m-%d_%Hh%Mm`     # Append date and time to backup fileSRCDIR=/srv                      # Location of directories to backupDESDIR=/srv/backup               # Destination of backup filesEXCLUDE=exclude.txt  # File which defines what to exclude from archivingfor dir in $SRCDIR/*/do  base=$(basename $dir)  if grep -Fxq $base $EXCLUDE  then    echo $base excluded  else    tar -cpzf $DESDIR/$base-$TIME.tar.gz $dir  fidone#END