DEV Community 👩‍💻👨‍💻

D
D

Posted on

OSXとGNU系コマンドを揃える

OSX

$ echo `date -d '1 day ago' +"%Y-%m-%d"`
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

$ echo `date -v-1d +"%Y-%m-%d"`
2014-10-23
$ 
Enter fullscreen mode Exit fullscreen mode

Linux

$ echo `date -d '1 day ago' +"%Y-%m-%d"`
2014-10-23
$ echo `date -v-1d +"%Y-%m-%d"`
date: invalid option -- 'v'
Try 'date --help' for more information.
Enter fullscreen mode Exit fullscreen mode

2つの環境揃えないとosxで書いたのがlinuxサーバーで動かない

$ brew install coreutils

All commands have been installed with the prefix 'g'.

If you really need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:

    PATH="/opt/boxen/homebrew/opt/coreutils/libexec/gnubin:$PATH"

Additionally, you can access their man pages with normal names if you add
the "gnuman" directory to your MANPATH from your bashrc as well:

    MANPATH="/opt/boxen/homebrew/opt/coreutils/libexec/gnuman:$MANPATH"

$ echo `gdate -d '1 day ago' +"%Y-%m-%d"`
2014-10-23

$ vim ~/.bashrc
alias date="gdate"
$ source ~/.bashrc

$ echo `date -d '1 day ago' +"%Y-%m-%d"` 
2014-10-23
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Find what you were looking for? Sign up so you can:

 
🌚 Enable dark mode
🔠 Change your default font
📚 Adjust your experience level to see more relevant content