title: How can I create nonexistent subdirectories recursively using Bash?
body: <p>I am creating a quick backup script that will dump some databases into a nice/neat directory structure and I realized that I need to test to make sure that the directories exist before I create them. The code I have works, but is there a better way to do it?</p>
  <pre><code>[ -d &quot;$BACKUP_DIR&quot; ] || mkdir &quot;$BACKUP_DIR&quot;
  [ -d &quot;$BACKUP_DIR/$client&quot; ] || mkdir &quot;$BACKUP_DIR/$client&quot;
  [ -d &quot;$BACKUP_DIR/$client/$year&quot; ] || mkdir &quot;$BACKUP_DIR/$client/$year&quot;
  [ -d &quot;$BACKUP_DIR/$client/$year/$month&quot; ] || mkdir &quot;$BACKUP_DIR/$client/$year/$month&quot;
  [ -d &quot;$BACKUP_DIR/$client/$year/$month/$day&quot; ] || mkdir &quot;$BACKUP_DIR/$client/$year/$month/$day&quot;
  </code></pre>