ablog

不器用で落着きのない技術者のメモ

bash で YYYYMMDD な名前のファイルを作成する

  • ファイルを作成する
for i in {0..364}
do
	YYMMDD=$(date --date "20180101 $i days" +%Y%m%d)
	echo ${YYMMDD} > table01_${YYMMDD}.txt
done
  • 作成したファイルを確認する
$ ls |head
table01_20180101.txt
table01_20180102.txt
table01_20180103.txt
table01_20180104.txt
table01_20180105.txt
table01_20180106.txt
table01_20180107.txt
table01_20180108.txt
table01_20180109.txt
table01_20180110.txt
$ ls |tail
table01_20181222.txt
table01_20181223.txt
table01_20181224.txt
table01_20181225.txt
table01_20181226.txt
table01_20181227.txt
table01_20181228.txt
table01_20181229.txt
table01_20181230.txt
table01_20181231.txt
$ aws s3 cp . s3://az-test-datalake/system01/table01/ --recursive
$ aws s3 ls s3://az-test-datalake/system01/table01/|head
2018-05-04 06:55:11          0
2018-05-04 07:14:12          9 table01_20180101.txt
2018-05-04 07:14:12          9 table01_20180102.txt
2018-05-04 07:14:12          9 table01_20180103.txt
2018-05-04 07:14:12          9 table01_20180104.txt
2018-05-04 07:14:13          9 table01_20180105.txt
2018-05-04 07:14:12          9 table01_20180106.txt
2018-05-04 07:14:12          9 table01_20180107.txt
2018-05-04 07:14:12          9 table01_20180108.txt
2018-05-04 07:14:12          9 table01_20180109.txt

$ aws s3 ls s3://az-test-datalake/system01/table01/|tail
2018-05-04 07:14:17          9 table01_20181222.txt
2018-05-04 07:14:17          9 table01_20181223.txt
2018-05-04 07:14:17          9 table01_20181224.txt
2018-05-04 07:14:17          9 table01_20181225.txt
2018-05-04 07:14:17          9 table01_20181226.txt
2018-05-04 07:14:17          9 table01_20181227.txt
2018-05-04 07:14:17          9 table01_20181228.txt
2018-05-04 07:14:17          9 table01_20181229.txt
2018-05-04 07:14:17          9 table01_20181230.txt
2018-05-04 07:14:17          9 table01_20181231.txt