LoginSignup
0
0

Linuxコマンドのワンライナーで連続した日付を生成したい

Posted at

Linuxコマンドで連続した日付を生成したいことがたまにあるので、自分用のメモとして残しておきます。たとえば2023/09/07から15日連続した日付を生成したい場合、次のようなワンライナーで実現可能です。

seq 0 14 | xargs -I{} date -d 2023/09/07+{}days +%Y/%m/%d

実行結果は以下の通りです。

2023/09/07
2023/09/08
2023/09/09
2023/09/10
2023/09/11
2023/09/12
2023/09/13
2023/09/14
2023/09/15
2023/09/16
2023/09/17
2023/09/18
2023/09/19
2023/09/20
2023/09/21

環境情報

$ seq --version
seq (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

作者 Ulrich Drepper。


$ xargs --version
xargs (GNU findutils) 4.7.0
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.


$ date --version
date (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

作者 David MacKenzie。
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0