我正在創建一個快速備份腳本,將一些數據庫轉儲到一個漂亮/整潔的目錄結構中,並且我意識到我需要測試以確保目錄在創建之前存在。代碼我有工作,但似乎有更好的方法來做到這一點。有什麼建議麼?如何使用Bash遞歸創建不存在的子目錄?
[ -d "$BACKUP_DIR" ] || mkdir "$BACKUP_DIR"
[ -d "$BACKUP_DIR/$client" ] || mkdir "$BACKUP_DIR/$client"
[ -d "$BACKUP_DIR/$client/$year" ] || mkdir "$BACKUP_DIR/$client/$year"
[ -d "$BACKUP_DIR/$client/$year/$month" ] || mkdir "$BACKUP_DIR/$client/$year/$month"
[ -d "$BACKUP_DIR/$client/$year/$month/$day" ] || mkdir "$BACKUP_DIR/$client/$year/$month/$day"
http://unix.stackexchange.com/questions/49263/recursive-mkdir – 2016-08-16 16:59:02