LoginSignup
5

More than 3 years have passed since last update.

Macでlsを叩いた時のエラー対処法

Last updated at Posted at 2019-05-08

macOS Mojave1lsを叩いたら次のようなエラーがでた。

ls: illegal option -- - usage

原因は~/.zshrcalias ls="ls --color"と色付けで出力してくれるオプションをつけたものにエイリアスを張っていたから。ls --colorはUbuntu (おそらくLinux全般的に)で動いていたが、Macではだめらしい。解決方法は以下の二つ。

その1: linux環境のlsを使うようにする

brew install coreutils

そして、以下を~/.bashrc (bashの場合)または ~/.zshrc (zshの場合)に追加し、パスを通してあげる。

export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"

その2: Mac標準のlsで頑張る

以下のエイリアスを張る。

alias ls="ls -G"

ただ、Linuxのlsよりも全体的に暗めの色が使われるようで背景が真っ黒だとかなり見辛い。
ただ、これはターミナルの色設定を変えればなんとなる気がする。

ちなみに、linuxとMacで-Gのオプションの意味が異なる。

  • Linux: -lで詳細出力した場合にグループ名を省略する
  • Mac: 色付けして出力

参考資料


  1. 正確には10.14.4 

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
5