LoginSignup
4
3

More than 5 years have passed since last update.

dateコマンドの色々様々

Posted at

拡張が無いと無理らしいですが、便利なのでメモ。
日付をスクリプトのコマンドライン引数に渡したりとかしたいことありますよね。

dateコマンドで一日前のタイムスタンプを取得する

date "1 days ago" +"%s"

dateコマンドで二日前の日付をスラ区切り

date "2 days ago" +"%Y/m/d"

シェルスクリプト内での利用例

#!/bin/bash
target_date="$1"
if [ -z $target_date ]; then
  target_date=`date -d "1 days ago" +"%Y/%m/%d"`
fi
echo $target_date

/path/to/command1 $target_date
/path/to/command2 $target_date
/path/to/command3 $target_date
/path/to/command4 $target_date
/path/to/command5 $target_date
4
3
0

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
4
3