How to create multiple directories in hadoop using single command?

I want to create 365 folders for every year. I added below for your reference what i tried. Please suggest me create multiple folders at one shot in hadoop 2.

hdfs dfs -mkdir /mnt/hadoop/Ram/Birla/home/inside/{dt=2016-11-01,dt=2016-11-02,dt=2016-11-03,dt=2016-11-04,dt=2016-11-05,dt=2016-11-06,dt=2016-11-07,dt=2016-11-08,dt=2016-11-09,dt=2016-11-10,dt=2016-11-11,dt=2016-11-12,dt=2016-11-13,dt=2016-11-14,dt=2016-11-15,dt=2016-11-16,dt=2016-11-17,dt=2016-11-18,dt=2016-11-19,dt=2016-11-20,dt=2016-11-21,dt=2016-11-22,dt=2016-11-23}

Upvotes: 1

Views: 2080

Answers (1)

adranale
adranale

Reputation: 2874

You can write a shell script where you start with a variable on '2016-01-01' and increment it in a loop till the end of the year, while executing your command inside the loop. Something like this:

FIRST_DAY="2016-01-01"
for i in {0..364}
do
   DAY=$(date +%m-%d-%Y -d "$FIRST_DAY + $i day")
   hdfs dfs -mkdir /mnt/hadoop/Ram/Birla/home/inside/$DAY
done

see How to increment a date in a bash script

Upvotes: 2

Related Questions