unix-cli-best-practices
БесплатноБез исполняемых скриптовНе проверенSafe, portable, and efficient command-line patterns for macOS/BSD Unix tools (grep, find, sed, awk, xargs, mdfind, pbcopy, open) and modern alternatives…
от flutter★ 3 224 звезды на GitHubОб этом скилле
Unix CLI best practices
This guide provides efficient, safe, and portable techniques for manipulating text and finding files from the command line on macOS. By default, macOS uses BSD-derived UNIX utilities (grep, find, sed, awk) which have subtle differences from their GNU/Linux counterparts.
When possible, use high-performance replacements (ripgrep and fd) which respect .gitignore rules by default and offer more ergonomic interfaces.
Modern high-performance alternatives
Use these tools instead of standard BSD utilities for local codebase operations.
ripgrep (rg)
Use ripgrep (rg) as the preferred tool for searching text. It is faster than standard grep and respects .gitignore rules by default.
Common use cases:
- Run
rg 'search_term'to recursively search the current directory. - Run
rg -S 'term'to search case-insensitively unless the query contains uppercase letters. Userg -i 'term'for strict case-insensitivity. - Run
rg -g '*.ts' -g '!*.spec.ts' 'term'to search.tsfiles while excluding.spec.tsfiles. - Run
rg -v 'ignore_me'to print lines that do not match the pattern. - Run
rg -l 'term'to list only the names of matching files. Combine withrg -0for null-terminated output suitable forxargs. - Run
rg -F 'foo()'to treat the search pattern as a fixed string rather than a regular expression. - Run
rg -w 'const'to match whole words only. - Run
rg -C 2 'term'to show two lines of surrounding context. Userg -B 2for preceding context orrg -A 2for succeeding context.
Refer to rg --help for the complete options list.
fd
Use fd as the preferred tool for traversing the filesystem and finding files. It is faster than standard find and respects .gitignore rules by default.
Common use cases:
- Run
fd 'pattern'to find files matching the regex pattern anywhere in their path. - Run
fd -e py -e txtto filter results by file extensions. - Run
fd -t d 'docs'to find directories. Usefd -t ffor files andfd -t lfor symbolic links. - Run
fd -Hto include hidden files, orfd -Ito include ignored files (such asnode_modules). Combine asfd -HIto search all files. - Run
fd -p 'src/assets'to match the pattern against the full path instead of just the filename. - Run
fd -e log -x rmto execute a command on each matching file individually. Use-X(e.g.,fd -e log -X rm) to run the command once with all matching files as arguments. - Run
fd -a 'pattern'to return absolute paths instead of relative paths.
Refer to fd --help for the complete options list.
Built-in tools for macOS and BSD
Use these built-in utilities only when rg and fd are unavailable. Apply precise filters to prevent performance degradation.
Efficient searching with grep
Do not use grep | grep -v 'unwanted_dir' to exclude directories. This approach reads all files before filtering them. Use native exclusion arguments instead to exclude directories at the filesystem level:
# Slow: reads binary and ignored files
grep -R "pattern" . | grep -v "node_modules"
# Fast: skips the directory completely at the filesystem level
grep -R --exclude-dir=node_modules --exclude-dir=.git "pattern" .
Common grep flags:
-ror-Rto search recursively.-Rfollows symbolic links, while-rdoes not.-Ito ignore binary files for faster execution and clean output.--exclude="*.min.js"to ignore files matching a specific glob.--include="*.dart"to search only files matching a specific glob.-lto print only the names of files containing matches.-Zto print a null character after each filename, which is useful when piping toxargs -0.
Example of safely deleting files containing a specific string:
grep -rlZ -I --exclude-dir=node_modules "DEPRECATED_API" . | xargs -0 rm
High-performance traversal with find
Prevent find from traversing irrelevant directory trees by using the -prune option.
# Slow: traverses node_modules entirely, then filters output
find . -name "*.ts" | grep -v "node_modules"
# Fast: skips node_modules entirely
find . -name "node_modules" -prune -o -name "*.ts" -print
The expression -name "node_modules" -prune stops traversal when encountering a node_modules directory. The -o (OR) operator specifies that for any other directory or file ending in .ts, the path is printed.
macOS portability with sed
macOS uses BSD sed, which differs from GNU sed in its handling of in-place editing.
Use the -i option with an explicit backup extension. To edit in-place without creating a backup, provide an empty string:
# Edit in-place without creating a backup
sed -i '' 's/oldName/newName/g' filename.txt
# Edit in-place and create a backup named filename.txt.bak
sed -i '.bak' 's/oldName/newName/g' filename.txt
Use the -E option to enable extended regular expressions, avoiding the need to escape parentheses and plus signs:
Установить unix-cli-best-practices в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл unix-cli-best-practices?
Safe, portable, and efficient command-line patterns for macOS/BSD Unix tools (grep, find, sed, awk, xargs, mdfind, pbcopy, open) and modern alternatives (ripgrep, fd). Covers common shell scripting and one-liner use cases including fast searching, text processing, codebase navigation, and parallel execution.
Как установить скилл unix-cli-best-practices?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл unix-cli-best-practices запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic