DSD DSD - 1 year ago 106
Linux Question

Create directory structure in unix

I want to create directory structure based on year, month and julian day as given below.

/home/applications/app_name/year/month/julian day
e.g.: /home/applications/app_name/2016/June/155

I am writting a script to create such directories for next entire month and script will be scheduled monthly. if I am running the script on 01st of June, script should create all directories for month of July.

e.g: /home/applications/app_name/2016/July/(julian days)

Thanks in Advance

Answer Source
current_year=$(date +%Y)
next_month=$(($(date +%m) + 1))
locale_next_month=$(date -d$current_year/$next_month/1 +%B)

for day_of_month in $(seq 1 31)
  if day_of_year=$(date -d$current_year/$next_month/$day_of_month +%j 2> /dev/null)
    mkdir -p /home/applications/app_name/$current_year/$locale_next_month/$day_of_year