fd - 빠르고 사용자 친화적인 Find 대안 치트시트
설치
| 플랫폼 | 명령어 |
|---|
| Ubuntu/Debian | sudo apt install fd-find (binary: fdfind) |
| Arch Linux | sudo pacman -S fd |
| Fedora/RHEL | sudo dnf install fd-find |
| Alpine Linux | apk add fd |
| macOS (Homebrew) | brew install fd |
| macOS (MacPorts) | sudo port install fd |
| Windows (Scoop) | scoop install fd |
| Windows (Chocolatey) | choco install fd |
| Windows (Winget) | winget install sharkdp.fd |
| Cargo (All platforms) | cargo install fd-find |
| Snap | sudo snap install fd |
기본 명령어
| 명령어 | 설명 |
|---|
fd filename | ”filename”과 일치하는 파일/디렉토리 검색 |
fd pattern /path | 특정 디렉토리에서 패턴 검색 |
fd -e txt | .txt 확장자를 가진 모든 파일 찾기 |
fd -e js -e ts | 다중 확장자(.js 또는 .ts)를 가진 파일 찾기 |
fd -t f pattern | 디렉토리가 아닌 파일만 찾기 |
fd -t d dirname | 디렉토리만 찾기 |
fd -t x | 실행 가능한 파일만 찾기 |
fd -t l | 심볼릭 링크만 찾기 |
fd -s Pattern | 대소문자 구분 검색 (기본값은 대소문자 구분 없음) |
fd -d 3 pattern | 검색 깊이를 3 레벨로 제한 |
fd -H pattern | 검색에 숨겨진 파일 포함 |
fd -I pattern | .gitignore 규칙을 무시하지 마세요 |
fd -a pattern | 상대 경로 대신 절대 경로 표시 |
fd -l pattern | Show detailed listing (like ls -l) |
fd -0 pattern | Use null separator (for piping to xargs -0) |
고급 사용법
| 명령어 | 설명 |
|---|
fd '^test.*\.js$' | regex 패턴 사용 (파일명이 “test”로 시작하고 .js로 끝나는 파일) |
fd -g '*.{js,ts}' | glob 패턴을 regex 대신 사용하세요 |
fd -F 'exact.string' | 고정 문자열 검색 (정규 표현식 해석 없음) |
fd -E node_modules -E '*.tmp' pattern | 검색에서 특정 패턴 제외하기 |
fd --no-ignore pattern | .gitignore, .fdignore, 또는 .ignore 파일을 사용하지 마세요 |
fd -L pattern | 검색 중 심볼릭 링크 따라가기 |
fd --changed-within 2d | 최근 2일 내에 수정된 파일들 |
fd --changed-before 30d | 최근 30일 동안 수정되지 않은 파일들 |
fd --size +100m | 100MB보다 큰 파일들 |
fd --size +10m --size -100m | 10MB에서 100MB 사이의 파일들 |
fd --owner username | 특정 사용자가 소유한 파일 |
fd --max-results 100 | 결과를 100개로 제한 |
fd -x rm {} | 각 결과에 대해 명령 실행 (파일 삭제) |
fd -X convert {} {.}.png | 여러 인자로 명령 실행 (일괄 변환) |
fd --color never pattern | 색상 출력 비활성화 |
fd --strip-cwd-prefix pattern | Remove ./ prefix from results |
fd -H -t d "^\." | 숨겨진 디렉토리 (점(.)으로 시작하는) 찾기 |
fd -t f -x du -h {} | 모든 일치 항목의 파일 크기 표시 |
fd pattern --threads 1 | 단일 스레드 사용 (디버깅용) |
fd --base-directory /path pattern | 검색을 위한 기본 디렉토리 변경 |
구성
구성 파일
전역 무시 파일 위치:
- Linux/macOS:
~/.config/fd/ignore또는 ~/.fdignore
- Windows:
%APPDATA%\fd\ignore
프로젝트별: .fdignore프로젝트 루트에 있음
.fdignore 파일 예시
# Ignore dependency directories
node_modules/
vendor/
target/
# Ignore build outputs
build/
dist/
*.o
*.pyc
# Ignore IDE directories
.idea/
.vscode/
*.swp
# Ignore log files
*.log
logs/
# Ignore temporary files
*.tmp
*~
.DS_Store
# Ignore specific paths
/cache/
/tmp/
환경 변수
# Set default options for all fd commands
export FD_OPTS="--hidden --follow --exclude .git"
# Control colorization (fd respects LS_COLORS)
export LS_COLORS="di=34:ln=35:ex=31:*.txt=33"
유용한 별칭
# Add to ~/.bashrc or ~/.zshrc
# Search including hidden files
alias fdh='fd -H'
# Search ignoring .gitignore
alias fda='fd -I'
# Find large files
alias fdl='fd --size +100m'
# Find recent files (last 24 hours)
alias fdr='fd --changed-within 1d'
# Find and preview with fzf and bat
alias fdf='fd -t f | fzf --preview "bat --color=always {}"'
# Find and edit with vim
alias fdv='fd -t f | fzf | xargs -r vim'
일반적인 사용 사례
사용 사례 1: 빌드 아티팩트 정리
# Remove all Python compiled files
fd -e pyc -e pyo -x rm {}
# Remove all node_modules directories (up to 2 levels deep)
fd -t d -d 2 '^node_modules$' -x rm -rf {}
# Clean old log files (older than 30 days)
fd -e log --changed-before 30d -x rm {}
# Remove all temporary files
fd -g '*.tmp' -g '*~' -g '*.swp' -x rm {}
사용 사례 2: 코드 검색 및 분석
# Find all JavaScript/TypeScript files modified in last week
fd -e js -e ts -e jsx -e tsx --changed-within 7d
# Count lines of code in Rust project
fd -e rs -x wc -l {} | awk '{sum+=$1} END {print sum}'
# Find all TODO comments in Python files
fd -e py -x grep -Hn "TODO:" {}
# Find largest source files
fd -e java -e kt -x du -h {} | sort -hr | head -20
# Find files containing specific function name
fd -e cpp -e hpp -x grep -l "myFunction" {}
사용 사례 3: 로그 파일 관리
# Find and compress logs older than 7 days
fd -e log --changed-before 7d -x gzip {}
# Search for errors in recent logs
fd -e log --changed-within 1d -x grep -i "error" {} \;
# Find large log files (over 100MB)
fd -e log --size +100m -l
# Archive old logs to separate directory
fd -e log --changed-before 30d -x mv {} /archive/logs/
사용 사례 4: Docker 및 컨테이너 관리
# Find all Dockerfiles in project
fd -g '*Dockerfile*' -g 'Dockerfile.*'
# Find all docker-compose files
fd -g 'docker-compose*.yml' -g 'docker-compose*.yaml'
# Find and validate Dockerfiles
fd '^Dockerfile$' -x docker build --dry-run -f {} .
# Find container-related configs
fd -e yml -e yaml -x grep -l "kind:" {} \;
사용 사례 5: 보안 및 권한 감사
# Find world-writable files (security risk)
fd -t f -x sh -c 'test -w {} && ls -l {}'
# Find SUID/SGID binaries
fd -t x -x sh -c 'test -u {} -o -g {} && ls -l {}'
# Find files with passwords in name
fd -i password -i passwd -i secret
# Find configuration files with potential secrets
fd -g '*.conf' -g '*.cfg' -g '*.ini' -x grep -i "password\|secret\|key" {}
# Find SSH keys
fd -g 'id_rsa*' -g 'id_ed25519*' -H
모범 사례
- 다음 파일 사용
.fdignore: 프로젝트별 무시 패턴을 생성하여 검색 속도 향상 및 노이즈 감소
- 스마트 기본값 활용:
fd자동으로 존중.gitignore- 무시된 파일이 필요할 때만 사용-I- 다른 도구와 결합: 파이프fd출력을xargs,grep,fzf에 대한 강력한 워크플로우
- 다음과 함께 사용
-0``xargs: 항상fd -0 | xargs -0를 공백이나 특수 문자가 있는 파일 이름에 사용
- 파이프보다 선호:
-x를 사용fd -x command {}대신 xargs에 파이프하여 더 나은 성능 얻기
- 깊이 제한 설정: 과도한 재귀를 방지하기 위해 대규모 디렉토리 트리에서
-d플래그 사용
- 특정 유형 필터 사용: 검색 공간을 줄이기 위해 초기에 유형(
-t f,-t d)으로 필터링
- 별칭 생성: 자주 사용되는
fd패턴에 대한 셸 별칭 설정으로 타이핑 절약
- 시간 및 크기 필터 결합: 정확한 파일 대상을 위해
--changed-within와 --size함께 사용
- 정규식 패턴 테스트: 복잡한
fd검색 전에 온라인 정규식 테스터로 패턴 확인
문제 해결
| 문제 | 솔루션 |
|---|
Command not found: fd | On Debian/Ubuntu, binary is fdfind. Create symlink: ln -s $(which fdfind) ~/.local/bin/fd |
| Too many results | Use depth limit -d 3, exclude patterns -E node_modules, or filter by type -t f |
| Not finding hidden files | Add -H flag to include hidden files, or -HI to also ignore .gitignore rules |
| Search is too slow | Reduce depth with -d, exclude large directories with -E, or use --threads to control parallelism |
| Regex not matching | Remember fd uses case-insensitive search by default. Use -s for case-sensitive or -F for literal strings |
| Files in .gitignore showing up | This shouldn’t happen by default. Check for -I or --no-ignore flags in aliases or FD_OPTS |
| Special characters in filenames breaking commands | Use -0 with xargs -0 or use -x flag instead: fd pattern -x command {} |
| Cannot execute command on results | Check if using correct syntax: -x for individual execution, -X for batch execution |
| Color output in logs/files | Disable with --color never or redirect stderr: fd pattern 2>/dev/null |
| Permission denied errors | Redirect stderr to ignore: fd pattern 2>/dev/null or run with appropriate permissions |
| Not respecting .fdignore file | Ensure .fdignore is in project root or ~/.config/fd/ignore. Check file syntax matches .gitignore format |