LoginSignup
3
3

More than 5 years have passed since last update.

unixdayというコマンドをつくってみた

Posted at

たとえばMicrosoft Azureにインスタンスをつくるときcloudapp.netのサブドメインを3文字〜15文字の範囲で切るよう求められますが、考えるのが面倒なので「プレフィックス-UNIX日」(UNIX日というのはつまり1970年1月1日から何日経過したか。UNIX秒にすると長すぎるしかえって分かりづらい)というサブドメインを切ると決めます。

そこでunixdayというコマンドをつくってみました。単にdateコマンドでUnix秒を出して、それを1日=86400秒で割るだけです。

~/.bash.d/aliases
function unixday() {
    expr $(date +%s) / 86400
}

実際に実行すると以下のようになります(日本時間で2014年8月27日20時ごろの場合)。

exegesis:~ h12o$ unixday
16309
exegesis:~ h12o$ which unixday
unixday is a function
unixday () 
{ 
    expr $(date +%s) / 86400
}
exegesis:~ h12o$ 
3
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
3
3