0

I have the following directory structure:

/media/storage/sqlbackup/CUSTOMER1
/media/storage/sqlbackup/CUSTOMER2
...
/media/storage/sqlbackup/CUSTOMER*

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.

3
  • 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? Nov 22, 2019 at 18:09
  • 1
    So you want to create all missing subdirectories? Nov 22, 2019 at 18:10
  • Yes, @roaima. Correct.
    – Kahn
    Nov 22, 2019 at 18:10

1 Answer 1

6

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

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

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.

0

You must log in to answer this question.

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