C.W.K.
Stream
Lesson 01 of 05 · published

Brace expansion 과 advanced globbing

~10 min · brace, glob, extglob

Level 0창 구경꾼
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Brace expansion — 텍스트 생성

echo {a,b,c}.txt          # a.txt b.txt c.txt
echo {1..5}                # 1 2 3 4 5
echo {01..05}              # 01 02 03 04 05  (0 패딩)
echo {1..10..2}            # 1 3 5 7 9       (step)
echo {a..e}                # a b c d e
mkdir -p project/{src,test,docs}/{2025,2026}

Brace expansion 은 glob expansion 전에 일어나고 존재 안 하는 경로에서도 펼침 — 디렉터리 트리 생성에 완벽.

재귀 globbing

ls **/*.py                # zsh; bash 는 `shopt -s globstar` 필요
ls src/**/*.{ts,tsx}       # brace 와 결합

** 가 디렉터리 경계 넘어 매치 — 일상 케이스에선 find -name '*.py' 보다 훨씬 빠름.

zsh glob qualifier

ls *(.)                   # 일반 파일만
ls *(/)                   # 디렉터리만
ls *(.om)                 # 일반 파일, mtime 최신순
ls *(.OL[1,5])            # 가장 큰 일반 파일 5 개
ls *(.m-1)                # 최근 1 일 안에 수정된 일반 파일

zsh 전용. one-liner 에 짜릿할 만큼 강력.

extglob (bash)

shopt -s extglob
ls !(*.txt)                # .txt 빼고 다
ls @(foo|bar).log          # 정확히 foo.log 또는 bar.log
ls *(foo|bar)              # 0 회 이상

zsh 의 패턴 alternation 의 bash 등가. default off — shopt -s extglob.

Code

한 줄로 프로젝트 골격·bash
mkdir -p project/{src,tests,docs}/{python,rust}
find project -type d

External links

Exercise

mkdir -p sandbox/{a,b,c}/{1,2,3}; tree sandbox. 이어서 ls sandbox/**/* (zsh). 가장 큰 python 파일 5 개: ls -lh **/*.py(.OL[1,5]).

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.