macOS: gnu ls (coreutils) 로 바꾸려면?

macOS 에서 제공하는 ls 에서는 --time-style=long-iso 을 쓸 수가 없다. 이게 뭐냐하면..

% ll
total 0
drwx------   5 macuser staff  160 2023-03-24 20:36 Applications
drwx------+  3 macuser staff   96 2023-03-24 16:21 Desktop
drwx------+  3 macuser staff   96 2023-03-24 16:21 Documents
drwx------+ 25 macuser staff  800 2023-03-24 23:08 Downloads
drwx------+ 86 macuser staff 2.7K 2023-03-25 13:21 Library
drwx------   4 macuser staff  128 2023-03-24 17:26 Movies
drwx------+  5 macuser staff  160 2023-03-24 18:23 Music
drwx------+  4 macuser staff  128 2023-03-24 16:22 Pictures
drwxr-xr-x+  4 macuser staff  128 2023-03-24 16:21 Public

2023-03-24 가 바로 long-iso 다. macOS 용으로 그냥 실행하면,

% /bin/ls -l
total 0
drwx------@  5 macuser  staff   160  3 24 20:36 Applications
drwx------+  3 macuser  staff    96  3 24 16:21 Desktop
drwx------+  3 macuser  staff    96  3 24 16:21 Documents
drwx------+ 27 macuser  staff   864  3 26 20:17 Downloads
drwx------@ 86 macuser  staff  2752  3 25 13:21 Library
drwx------   4 macuser  staff   128  3 24 17:26 Movies
drwx------+  5 macuser  staff   160  3 24 18:23 Music
drwx------+  4 macuser  staff   128  3 24 16:22 Pictures
drwxr-xr-x+  4 macuser  staff   128  3 24 16:21 Public

이렇게 나온다. 언젠가부터 저렇게 보이는게 불편해서 저렇게 바꿨는데, 이건 gnu ls 에서만 제공이 된다고 한다. 즉, macOS 자체 ls 로는 저런 기능이 지원이 되지 않는다.

이를 위해서, Homebrew 가 먼저 설치돼 있어야 하고, 그를 통해 coreutils 를 설치해야 한다.
이 모든 사항은 Stackoverflow 에서 알아낼 수 있었다.


설치를 했다고 해서, 자동으로 ls 를 쓸 수 있다고 생각한다면 오산. 뒷처리도 해줘야 한다.
두가지 방법이 있는데, 아예 coreutils 에서 제공하는 프로그램들로 바꿔치기(?)하거나, 아니면 ls (또는 필요한 다른 것들) 만 alias 로 만들 수 있다.

alias 로 하려면 다음과 같이 해준다.

alias ls="/opt/homebrew/opt/coreutils/libexec/gnubin/ls"

바꿔치려면? 사실 바꿔친다기 보다는 /bin 실행 경로보다 gnu coreutils 실행 경로를 앞에 두는 방식인데, 이렇게 해주면 된다.

.zshrc 또는 .zprofile 에 다음 행들을 추가한다.

export PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:${PATH}"
export MANPATH="$(brew --prefix)/opt/coreutils/libexec/gnuman:${MANPATH}"

위 경로 모두 Apple Silicon 용 경로고, x86 과는 경로가 다르다.

Author: 아무도안

안녕하세요. 글 남겨주셔서 고맙습니다.