macOS에서 ls --time-style이 unrecognized option 오류를 낼 때: 날짜를 ISO 모양으로 찍는 맥의 방법을 직접 시험한 결과When ls --time-style fails with an unrecognized option error on macOS: how to print ISO-style dates with the Mac's own ls, tested directly
리눅스식 ls --time-style 줄을 맥에서 돌려 오류를 만났거나, 오류를 숨긴 스크립트가 빈 값을 받은 독자가 맥 ls 만으로 같은 날짜 모양을 내는 방법을 고르게 돕는다.
이 맥(26.6.2)의 ls 는 --time-style·--full-time·--sort·--human-readable 같은 GNU 긴 옵션을 종료 코드 1로 거부하고 TIME_STYLE 환경 변수도 읽지 않는다. 대신 ls -l -D '%Y-%m-%d %H:%M' 이 GNU 의 long-iso 와 시간 열부터 이름까지 한 줄도 다르지 않았고, 초까지 필요하면 -D '%Y-%m-%d %H:%M:%S' 를 쓰며, 소수 초는 -D 로 얻지 못한다.
스크립트의 ls --time-style 줄을 ls -l -D 형식 줄이나 stat -f 로 바꾸고, 맥의 -D 뒤에 형식 문자열을 반드시 붙였는지 확인하라.
목차
한 줄 요약: 맥의 ls 는 –time-style 을 종료 코드 1로 거부하지만, ls -l -D ‘%Y-%m-%d %H:%M’ 이 GNU 의 long-iso 와 같은 날짜 열을 내므로 그 형태로 바꾸면 된다.
리눅스에서 파일 수정 시각을 2026-10-29 23:31 처럼 찍던 ls -l --time-style=long-iso 를 맥 터미널에서 돌리면 목록 대신 오류 두 줄만 나온다. 이 글은 맥 ls 만으로 같은 모양을 내는 방법과 그 방법이 GNU ls 와 어디까지 같은지, 그리고 맥 ls 의 -D 옵션이 만드는 함정을 이 맥에서 직접 돌려 보인다.
ls: unrecognized option `--time-style=long-iso'
usage: ls [-@ABCFGHILOPRSTUWXabcdefghiklmnopqrstuvwxy1%,] [--color=when] [-D format] [file ...]
확인한 환경은 macOS 26.6.2 arm64 의 /bin/ls, 비교 기준으로 Homebrew 의 GNU coreutils 9.11 에 든 gls, bash 3.2.57 이고 날짜는 2026-10-29 이다. 시험 스크립트 네 개를 두 번씩 돌렸고 두 번째 결과는 첫 번째와 같았다. 다른 점은 소수 초를 보여 주는 GNU full-iso 한 줄뿐이었고 그것은 실행 때마다 다른 값이다. 같은 오류는 이미 공개돼 있다. 2023년 일본어 블로그 글은 ls -l --time-style=long-iso 가 맥에서 같은 unrecognized option 을 낸다고 보이고(그 글의 usage 줄에는 이 맥과 달리 옵션 글자 X 가 없다) coreutils 의 gls 를 쓰라고 안내한다.
용어 몇 개. GNU 는 많은 리눅스 배포판이 쓰는 명령 모음이고, 맥의 명령은 BSD 계열이라 같은 이름이어도 옵션이 다르다. 종료 코드는 명령이 끝나며 남기는 숫자로 0이 정상이다. strftime 형식은 %Y(연도)·%m(월)처럼 날짜 조각을 고르는 글자 모음이다. 맥 man ls 는 -D 를 “-l 로 길게 찍을 때 날짜와 시간을 strftime(3) 형식으로 찍는 옵션”으로 설명한다.
맥의 ls 가 거부하는 옵션과 받아 주는 옵션
파일 하나(a.txt)에 ls -l 옵션 을 붙여 종료 코드를 쟀다. 맥은 거부한 옵션마다 unrecognized option 과 usage 한 줄을 냈고, 종료 코드는 모두 1이었다. gls 는 아래 GNU 긴 옵션을 모두 0으로 받았다.
| 옵션 | 맥 /bin/ls |
gls 9.11 |
|---|---|---|
--time-style=long-iso, --time-style=full-iso, --full-time |
1 | 0 |
--time=ctime, --time=birth |
1 | 0 |
--sort=time, --group-directories-first |
1 | 0 |
--human-readable, --si |
1 | 0 |
--color=never |
0 | 0 |
-D %F, -T |
0 | 2 (-D 는 --dired 라서 %F 가 파일 이름이 되어 cannot access '%F', -T 는 칸 수를 받아 a.txt 가 칸 수로 읽혀 invalid tab size: 'a.txt') |
마지막 줄이 이 글의 둘째 이야기다. 같은 글자 -D 와 -T 가 맥에서는 날짜 형식과 전체 시각 옵션이고 GNU 에서는 다른 뜻이어서, ls 를 gls 의 별칭으로 바꾼 셸에 맥식 옵션을 넣으면 정반대로 실패한다. 환경 변수 TIME_STYLE=long-iso 는 gls 가 읽어 2026-10-29 23:31 을 찍었지만 맥은 읽지 않고 Oct 29 만 찍었다.
오류를 버리면 빈 값이 성공처럼 지나간다
오류 화면이 지저분해 2>/dev/null 을 붙이고 awk 로 날짜 열을 뽑으면 어떻게 되는지 쟀다. 변수에는 아무것도 담기지 않았고(길이 0) 파이프의 종료 상태는 1 0 이었다. pipefail 이 없으면 파이프 전체는 awk 의 0으로 끝난다. pipefail 을 켜면 1이 나왔다. ls ... || echo fallback 형태는 오류를 2>/dev/null 로 버린 경우, 출력을 모두 버린 경우, 오류를 그대로 둔 경우 세 가지 모두 맥에서 fallback 쪽을 탔다. 위험한 쪽은 || 없이 파이프로 값을 뽑는 경우다. 그러므로 ls --time-style 을 쓰던 스크립트를 맥으로 옮겼는데 날짜 칸이 비어 나온다면 2>/dev/null 과 pipefail 부재부터 의심한다.
맥 ls 로 같은 모양을 내는 방법
기본 ls -l 은 6개월보다 오래된 파일에 시각 대신 연도를 찍는다. 맥 man ls 는 “수정 시각이 6개월보다 과거나 미래이고 -D·-T 가 없으면 시·분 자리에 연도를 보여 준다”고 적는다. 이 시험의 항목 몇 개는 이렇게 갈렸다.
| 항목 | 맥 ls -l |
맥 ls -lT |
맥 ls -l -D '%Y-%m-%d %H:%M' |
|---|---|---|---|
| 폴더 d (2025-01-31) | Jan 31 2025 |
Jan 31 15:00:59 2025 |
2025-01-31 15:00 |
| old.txt (2024-01-02) | Jan 2 2024 |
Jan 2 03:04:05 2024 |
2024-01-02 03:04 |
| new.txt (오늘) | Oct 29 23:31 |
Oct 29 23:31:39 2026 |
2026-10-29 23:31 |
-D '%Y-%m-%d %H:%M' 의 결과를 gls -l --time-style=long-iso 와 비교했다. 권한·크기 앞쪽 다섯 열은 떼고 시간 열부터 이름까지를 정렬해 diff 했더니 폴더, 심볼릭 링크(link.txt -> new.txt), 공백이 든 이름(sp ace.txt)까지 여섯 줄이 모두 같았다. 초까지 필요하면 맥 -D '%Y-%m-%d %H:%M:%S' 가 gls --time-style='+%Y-%m-%d %H:%M:%S' 와 같은 여섯 줄을 냈다. 한계도 있다. GNU 의 full-iso 는 소수 초까지 찍지만(2026-10-29 23:31:39.677314545 +0900), 맥 -D '%N' 은 소수 초가 아니라 글자 N 만 찍었다. 시간대는 %z 로 +0900 이 나왔다. 소수 초가 꼭 필요하면 stat -f '%Fm' 파일 이 에포크 초를 소수부 6자리 이상과 함께 냈지만 ISO 모양은 아니었고, stat -f '%Sm' -t '%Y-%m-%d %H:%M:%S.%N' 도 .N 이라는 글자만 찍었다.
시간의 종류를 바꾸는 GNU 의 --time=birth 자리는 맥에서 -U 였다. 접근 시각은 -u, 상태 변경 시각은 -c 이고 모두 -D 와 함께 쓸 수 있었다. 시험에서 touch -a 로 접근 시각을 2026-01-01 01:01:01 로 바꾼 파일에 ls -l -u -D '%F %T' 가 그 값을 찍었다. 정렬은 표시 형식과 따로여서 ls -lt -D '%F %T' 는 가장 새로운 파일이 위였다. 맥 -D 가 -T 보다 앞서는지는 ls -lT -D '%F' 가 날짜만 찍는 것으로 확인했다. -l 없이 -D 만 주면 형식은 쓰이지 않고 이름만 나왔다.
맥의 -D 에서 조심할 세 곳
첫째, 형식 문자열을 빼먹으면 -D 가 뒤의 인자를 형식으로 먹는다. ls -l -D b.txt 는 b.txt 를 파일이 아니라 형식으로 읽어 현재 폴더 전체를 나열하면서 날짜 자리마다 글자 b.txt 를 찍었고 종료 코드는 0이었다. 빈 문자열 -D '' 도 오류 없이 날짜 열만 비웠다.
둘째, 로케일이다. LC_ALL=C 에서 Oct 28 09:10 이던 기본 날짜 열이 ko_KR.UTF-8 에서는 10월 28 09:10 이 됐고 -D '%b' 는 10월 이었다. -D '%c' 는 2026년 10월 28일 수요일 09시 10분 11초 처럼 공백이 든 긴 문자열이었다. 한글 파일 이름(한글 파일.txt)은 -D '%F %R' 에서 그대로 찍혔다.
셋째, 열 수다. -D '%F' 는 awk 가 7열로 읽었고 -D '%F %T' 는 8열이었다. 형식에 공백이 들면 이름이 한 칸씩 밀리므로 awk '{print $9}' 같은 줄은 형식을 바꾸면 깨진다. 스크립트에서 날짜만 필요하면 ls 출력을 자르는 대신 stat -f '%Sm %N' -t '%Y-%m-%d %H:%M' 파일 을 쓴다. 같은 파일에서 위 ls -D 와 같은 2026-10-28 09:10 b.txt 가 나왔다.
그대로 붙여 쓸 함수
ls 를 gls 의 별칭으로 바꾼 셸에서 맥식 ls -l -D '%Y-%m-%d %H:%M' a.txt 를 돌렸더니 gls 가 -D 를 --dired 로 읽어 cannot access '%Y-%m-%d %H:%M' 과 2가 나왔다. /bin/ls 절대 경로를 부르는 함수 lsiso 는 같은 셸에서 날짜 열을 ISO 모양으로 찍으며 0으로 끝났다. zsh 스크립트 파일에서도 결과가 같았다(별칭은 cannot access 와 2, 함수는 0). 두 시험 모두 스크립트 파일 안에서 별칭을 켠 것이라 대화형 셸의 설정과는 다를 수 있다.
lsiso() { /bin/ls -l -D '%Y-%m-%d %H:%M' "$@"; }
lsiso -t ~/Downloads | head
gls 를 이미 깔았다면 ls --time-style=long-iso 줄을 gls 로만 바꿔도 된다. 이 맥의 gls 는 Homebrew coreutils 9.11 이었다(설치 명령 자체는 시험하지 않았다). 맥 ls 인지 GNU 인지 스크립트가 알아내려면 ls --version 의 종료 코드를 쓴다. 맥은 unrecognized option 과 1, gls 는 ls (GNU coreutils) 9.11 과 0이었다.
시험하지 못한 것
리눅스에서 도는 GNU ls 는 쓰지 못했고 이 맥의 gls 9.11 이 대신했다(비교한 GNU 설명서 문서는 9.12 판이다). 다른 macOS 버전, 소유자·권한·크기 열 같은 시간 이외의 열, iso 와 locale 스타일, 개행으로 나눈 두 줄 형식, fish 같은 다른 셸에서의 별칭 동작, 확장 속성이 붙은 @ 열의 의미, 아주 큰 폴더에서의 속도는 시험하지 않았다. 시간대는 Asia/Seoul 한 가지로만 돌렸다. 공개 기록은 증상을 확인하는 근거로만 썼고 검색량은 재지 않았다.
세 줄 요약
- 이 맥(26.6.2)의 ls 는 –time-style·–full-time·–sort 등 GNU 긴 옵션을 종료 코드 1로 거부하고 TIME_STYLE 환경 변수도 읽지 않았다.
- 2>/dev/null 로 오류를 버리고 awk 로 뽑으면 변수가 비는데도 pipefail 이 없으면 0으로 끝나므로, 스크립트를 맥으로 옮길 때 이 조합을 먼저 의심한다.
- ls -l -D ‘%Y-%m-%d %H:%M’ 은 GNU long-iso 와 시간 열부터 이름까지 같았고, -D 뒤에 형식을 빼먹으면 인자를 먹으며 소수 초는 맥 기본 도구 중 -D 로는 못 얻고 stat -f ‘%Fm’ 의 에포크 숫자로만 얻었다.
To help a reader who ran a Linux-style ls --time-style line on a Mac and hit an error, or whose script hid the error and received an empty value, find a way to print the same date shape with the Mac's own ls.
The ls on this Mac (26.6.2) rejects GNU long options such as --time-style, --full-time, --sort and --human-readable with exit code 1 and does not read the TIME_STYLE environment variable. Instead, ls -l -D '%Y-%m-%d %H:%M' did not differ by a single line from GNU long-iso from the time column through the name; use -D '%Y-%m-%d %H:%M:%S' when seconds are needed, and note that fractional seconds cannot be had with -D.
Replace ls --time-style lines in your scripts with an ls -l -D format line or stat -f, and check that every Mac -D is followed by a format string.
Contents
One-line summary: The Mac’s ls rejects –time-style with exit code 1, but ls -l -D ‘%Y-%m-%d %H:%M’ produces the same date column as GNU long-iso, so switch to that form.
If you run ls -l --time-style=long-iso, which prints modification times like 2026-10-29 23:31 on Linux, in a Mac terminal, you get two lines of error instead of a listing. This article shows, by running them on this Mac, how to produce the same shape with the Mac’s own ls, how far that method matches GNU ls, and what traps the Mac ls option -D sets.
ls: unrecognized option `--time-style=long-iso'
usage: ls [-@ABCFGHILOPRSTUWXabcdefghiklmnopqrstuvwxy1%,] [--color=when] [-D format] [file ...]
The environment I checked is /bin/ls on macOS 26.6.2 arm64, gls from Homebrew’s GNU coreutils 9.11 as the comparison baseline, and bash 3.2.57, on 2026-10-29. I ran the four test scripts twice each, and the second result matched the first. The only difference was one line of GNU full-iso that shows fractional seconds, which is a different value on every run. The same error is already public. A 2023 Japanese blog post shows that ls -l --time-style=long-iso produces the same unrecognized option on a Mac (the usage line in that post lacks the option letter X that this Mac’s has) and advises using coreutils’ gls.
A few terms. GNU is the command collection that many Linux distributions use, and the Mac’s commands are BSD-family, so options differ even under the same name. An exit code is the number a command leaves when it finishes, and 0 means success. A strftime format is a set of letters that pick pieces of a date, such as %Y (year) and %m (month). The Mac man ls describes -D as an option that prints the date and time in strftime(3) format when printing in long -l form.
Options the Mac’s ls rejects and options it accepts
I attached ls -l option to a single file (a.txt) and measured the exit code. For every option it rejected, the Mac printed unrecognized option and one usage line, and the exit code was always 1. gls accepted all of the GNU long options below with 0.
| Option | Mac /bin/ls |
gls 9.11 |
|---|---|---|
--time-style=long-iso, --time-style=full-iso, --full-time |
1 | 0 |
--time=ctime, --time=birth |
1 | 0 |
--sort=time, --group-directories-first |
1 | 0 |
--human-readable, --si |
1 | 0 |
--color=never |
0 | 0 |
-D %F, -T |
0 | 2 (-D is --dired, so %F becomes a file name and gives cannot access '%F'; -T takes a column count, so a.txt is read as that count and gives invalid tab size: 'a.txt') |
The last row is the second story of this article. The same letters -D and -T are a date format and a full-time option on the Mac but mean something else in GNU, so if you alias ls to gls in a shell and then feed it Mac-style options, it fails in the opposite way. The environment variable TIME_STYLE=long-iso was read by gls, which printed 2026-10-29 23:31, but the Mac did not read it and printed only Oct 29.
Discard the error and an empty value slips by as success
I measured what happens when you add 2>/dev/null because the error screen is messy and pull the date column with awk. Nothing was stored in the variable (length 0) and the pipeline’s exit status was 1 0. Without pipefail, the whole pipeline ends with the 0 of awk. With pipefail turned on, it gave 1. The form ls ... || echo fallback took the fallback branch on the Mac in all three cases: with the error discarded by 2>/dev/null, with all output discarded, and with the error left visible. The dangerous case is pulling a value through a pipe without any ||. So if you moved a script that used ls --time-style to the Mac and the date column comes out empty, suspect 2>/dev/null and the absence of pipefail first.
How to get the same shape with the Mac’s ls
A plain ls -l prints the year instead of the time for files older than six months. The Mac man ls says that if the modification time is more than six months in the past or future and -D or -T is not given, the year is shown in place of the hour and minute fields. A few items in this test came out as follows.
| Item | Mac ls -l |
Mac ls -lT |
Mac ls -l -D '%Y-%m-%d %H:%M' |
|---|---|---|---|
| Folder d (2025-01-31) | Jan 31 2025 |
Jan 31 15:00:59 2025 |
2025-01-31 15:00 |
| old.txt (2024-01-02) | Jan 2 2024 |
Jan 2 03:04:05 2024 |
2024-01-02 03:04 |
| new.txt (today) | Oct 29 23:31 |
Oct 29 23:31:39 2026 |
2026-10-29 23:31 |
I compared the result of -D '%Y-%m-%d %H:%M' with gls -l --time-style=long-iso. I cut the five leading permission-and-size columns, sorted from the time column through the name, and ran diff; all six lines were the same, including the folder, the symbolic link (link.txt -> new.txt) and the name containing a space (sp ace.txt). When seconds are needed, the Mac -D '%Y-%m-%d %H:%M:%S' gave the same six lines as gls --time-style='+%Y-%m-%d %H:%M:%S'. There are limits too. The GNU full-iso prints down to fractional seconds (2026-10-29 23:31:39.677314545 +0900), but the Mac -D '%N' printed only the letter N, not fractional seconds. The time zone came out as +0900 with %z. If you really need fractional seconds, stat -f '%Fm' file gave epoch seconds with six or more fractional digits, though not in ISO shape, and stat -f '%Sm' -t '%Y-%m-%d %H:%M:%S.%N' also printed only the characters .N.
The place of GNU’s --time=birth, which changes the kind of time, was -U on the Mac. Access time is -u and status-change time is -c, and all of them could be used together with -D. In the test, ls -l -u -D '%F %T' printed 2026-01-01 01:01:01 for a file whose access time I had changed to that value with touch -a. Sorting is separate from the display format, so ls -lt -D '%F %T' put the newest file on top. That the Mac -D takes precedence over -T was confirmed by ls -lT -D '%F' printing only the date. When -D was given without -l, the format was not used and only the names appeared.
Three places to be careful with the Mac’s -D
First, if you leave out the format string, -D eats the following argument as the format. ls -l -D b.txt read b.txt as a format rather than a file, listed the whole current folder, printed the text b.txt in every date slot, and the exit code was 0. An empty string -D '' also just blanked the date column without any error.
Second, the locale. The default date column that read Oct 28 09:10 under LC_ALL=C became 10월 28 09:10 under ko_KR.UTF-8, and -D '%b' gave 10월. -D '%c' was a long string with spaces such as 2026년 10월 28일 수요일 09시 10분 11초. A file with a Korean name was printed unchanged under -D '%F %R'.
Third, the column count. awk read -D '%F' as 7 columns and -D '%F %T' as 8. If the format contains a space, the name shifts by one column, so a line such as awk '{print $9}' breaks when you change the format. If a script needs only the date, use stat -f '%Sm %N' -t '%Y-%m-%d %H:%M' file instead of cutting ls output. On the same file it gave 2026-10-28 09:10 b.txt, the same as the ls -D above.
A function you can paste as it is
In a shell where ls was aliased to gls, running the Mac-style ls -l -D '%Y-%m-%d %H:%M' a.txt made gls read -D as --dired, giving cannot access '%Y-%m-%d %H:%M' and 2. The function lsiso, which calls /bin/ls by absolute path, ended with 0 in the same shell and printed the date column in ISO shape. The result was the same in a zsh script file (the alias gave cannot access and 2, the function 0). Both tests turned on the alias inside a script file, so an interactive shell’s configuration may differ.
lsiso() { /bin/ls -l -D '%Y-%m-%d %H:%M' "$@"; }
lsiso -t ~/Downloads | head
If you have already installed gls, you can also just change the ls --time-style=long-iso line to gls. The gls on this Mac was Homebrew’s coreutils 9.11 (I did not test the install command itself). To let a script find out whether it is the Mac ls or GNU, use the exit code of ls --version. The Mac gave unrecognized option and 1, and gls gave ls (GNU coreutils) 9.11 and 0.
What I could not test
I could not use the GNU ls that runs on Linux, and this Mac’s gls 9.11 stood in for it (the GNU manual page I compared against is the 9.12 edition). I did not test other macOS versions, columns other than time such as owner, permissions and size, the iso and locale styles, a two-line format split by a newline, alias behavior in other shells such as fish, the meaning of the @ column that marks extended attributes, or speed in very large folders. I ran only one time zone, Asia/Seoul. I used the public record only as evidence of the symptom and did not measure search volume.
Three-line summary
- The ls on this Mac (26.6.2) rejected GNU long options such as –time-style, –full-time and –sort with exit code 1 and did not read the TIME_STYLE environment variable.
- If you discard the error with 2>/dev/null and pull values with awk, the variable is empty yet the pipeline ends with 0 without pipefail, so suspect that combination first when moving a script to a Mac.
- ls -l -D ‘%Y-%m-%d %H:%M’ matched GNU long-iso from the time column through the name; leaving out the format after -D makes it eat an argument, and among the Mac’s default tools fractional seconds came only from the epoch number of stat -f ‘%Fm’, not from -D.