LoginSignup
0
0

More than 3 years have passed since last update.

macOSコマンドチートシート

Last updated at Posted at 2018-05-24

サーバではまだいろいろ使われてますが、ワークステーション用途としてはmacOSが最後の商用UNIXになってしまったようだ。

クリックでカーソルを移動する

Terminal.appでoptionを押しながらカーソルを移動したい場所をクリックすると、クリックでカーソルを移動することができる。

画像をリサイズする

sips が使えます。

以下のようにoriginalディレクトリに複数個ある画像ファイルがあるとする。

$ tree
.
├── original
│   ├── IMG_4641.jpg
│   ├── IMG_4642.jpg
│   ├── IMG_4643.jpg
│   ├── IMG_4644.jpg
│   ├── IMG_4645.jpg
│   ├── IMG_4646.jpg
│   ├── IMG_4647.jpg
│   ├── IMG_4648.jpg
│   ├── IMG_4649.jpg
│   └── IMG_4650.jpg
└── resized

2 directories, 10 files

縦横どちらか大きいほうが最大1024pxになるようにリサイズする

ls original/ | xargs -IXXX sips -Z 1024 original/XXX --out resized/XXX

周囲のWiFiのSSID一覧を取得する

  • airportコマンドを使う
  • なぜかパスが通ってない
$ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s
                            SSID BSSID             RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
                   502HWa-B0CEC4 xx:xx:xx:xx:xx:xx -79  11,-1   Y  -- WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP) 
                 atre_Free_Wi-Fi xx:xx:xx:xx:xx:xx -84  6       Y  -- NONE
                  X03B-89m6274IR xx:xx:xx:xx:xx:xx -91  36,+1   Y  JP NONE
                 atre_Free_Wi-Fi xx:xx:xx:xx:xx:xx -84  1       Y  -- NONE
.
. 中略
.
WPA2(PSK/AES,TKIP/TKIP) 
                   TLOG_ZP500111 xx:xx:xx:xx:xx:xx -66  1       Y  -- WPA(PSK/TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP) 
               SPWN_N34_7ca78b_2 xx:xx:xx:xx:xx:xx -70  1       N  JP WEP
                 SPWN_N34_7ca78b xx:xx:xx:xx:xx:xx -69  1       Y  JP WPA(PSK/AES/AES) WPA2(PSK/AES/AES) 

1 IBSS network found:
                            SSID BSSID             RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
                   1928434111071 xx:xx:xx:xx:xx:xx -70  13      Y  -- WEP

応用例 -> https://qiita.com/miminashi/items/2685de52147eb3a47534

GUIでdiffを見る

Xcodeいれてれば使えるのかな?

$ opendiff file1 file2

フォントの一覧を見る

$ system_profiler SPFontsDataType

from: https://apple.stackexchange.com/questions/35852/list-of-activated-fonts-with-shell-command-in-os-x

DNSスタブリゾルバのキャッシュを削除する

sudo killall -HUP mDNSResponder

実行ファイルが動的リンクしているライブラリの一覧を見る

Linuxだとlddで見れるやつ。
otool -Lを使う。

$ otool -L gtk-server-gtk3
gtk-server-gtk3:
    /usr/local/opt/gtk+3/lib/libgtk-3.0.dylib (compatibility version 2405.0.0, current version 2405.4.0)
    /usr/local/opt/gtk+3/lib/libgdk-3.0.dylib (compatibility version 2405.0.0, current version 2405.4.0)
    /usr/local/opt/pango/lib/libpangocairo-1.0.0.dylib (compatibility version 4201.0.0, current version 4201.4.0)
    /usr/local/opt/pango/lib/libpango-1.0.0.dylib (compatibility version 4201.0.0, current version 4201.4.0)
    /usr/local/opt/atk/lib/libatk-1.0.0.dylib (compatibility version 23210.0.0, current version 23210.1.0)
    /usr/local/opt/cairo/lib/libcairo-gobject.2.dylib (compatibility version 11603.0.0, current version 11603.0.0)
    /usr/local/opt/cairo/lib/libcairo.2.dylib (compatibility version 11603.0.0, current version 11603.0.0)
    /usr/local/opt/gdk-pixbuf/lib/libgdk_pixbuf-2.0.0.dylib (compatibility version 3801.0.0, current version 3801.1.0)
    /usr/local/opt/glib/lib/libgio-2.0.0.dylib (compatibility version 6001.0.0, current version 6001.4.0)
    /usr/local/opt/glib/lib/libgobject-2.0.0.dylib (compatibility version 6001.0.0, current version 6001.4.0)
    /usr/local/opt/glib/lib/libglib-2.0.0.dylib (compatibility version 6001.0.0, current version 6001.4.0)
    /usr/local/opt/gettext/lib/libintl.8.dylib (compatibility version 10.0.0, current version 10.6.0)
    /usr/lib/libffi.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1)

[できてなくない?] sudo ddをパスワードなしで実行できるようにする

  • SDにディスクイメージ書き込むのによく使うので
  • 最初、/dev/rdisk2のパーミッションを恒久的に変更する方法を探していたけど、macOSだと難しそうだったのでsudoで対応することにした
$ sudo tee /private/etc/sudoers.d/dd <<EOF
> miminashi ALL=(ALL) NOPASSWD: /bin/dd
> EOF

Xcodeなしで Command Line Tools for Xcode だけいれる

  1. https://developer.apple.com/download/more/ から Command Line Tools for Xcode 11.3.1 (2020/01/30 時点)をダウンロードしてインストールする
  2. sudo xcode-select --switch /Library/Developer/CommandLineTools/

ログインシェルをhomebrewでいれたbashにする

Catalinaでもこれでいけた

$ brew install bash
$ sudo vim /etc/shells  # 末尾に /usr/local/bin/bash を追加する
$ chsh  # ログインシェルに /usr/local/bin/bash を指定する

gitで補完を有効にしたい

  • homebrewでいれた bash_completion が有効化された状態でhomebrewでgitをいれると、補完定義が自動的に配置される
$ brew install bash-completion
$ brew install git
$ printf '[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"' >> ~/.bash_profile
0
0
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
0
0