I have the following directory structure:


Each CUSTOMER* directory may contain subdirectories named daily, weekly, and monthly. If a CUSTOMER* directory does not contain daily OR weekly OR monthly, I want it to be created, if it does, then I want it to remain.

Before: CUSTOMER1/daily

After: CUSTOMER1/{daily,weekly,monthly}

I was trying to do this with clever use of find, but trying to return all that don't match.

  • 1
    What do you want created if there are no daily, weekly, monthly directories for a given customer? All of them? Just one? Which one? Commented Nov 22, 2019 at 18:09
  • 1
    So you want to create all missing subdirectories? Commented Nov 22, 2019 at 18:10
  • Yes, @roaima. Correct.
    – Kahn
    Commented Nov 22, 2019 at 18:10

1 Answer 1


You can create the directories while hiding any error related to the directory already existing:

for custDir in /media/storage/sqlbackup/CUSTOMER*
    mkdir -p "$custDir"/{daily,weekly,monthly}

You cannot use /media/storage/sqlbackup/CUSTOMER*/{daily,weekly,monthly} because the {...} sequence is expanded before the wildcard, and a wildcard pattern will only match files/directories that exist.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .