CLI
Collections
- The Art of Command Line
- ๐ค just is a handy way to save and run project-specific commands.
- Structured text tools - The following is a list of text-based file formats and command line tools for manipulating each.
- ls-lint - An extremely fast directory and filename linter - Bring some structure to your project filesystem
- mise-en-place - dev tools, env vars, task runner
- Flox is a virtual environment and package manager all in one.
- Terminal Text Effects
- chezmoi - Manage your dotfiles across multiple diverse machines, securely.
- dotenvx - a better dotenvโfrom the creator of
dotenv
.- run anywhere (cross-platform)
- multi-environment
- encrypted envs
- Solarized - Precision colors for machines and people
Shell
- try lets you run a command and inspect its effects before changing your live system.
try
uses Linux's namespaces (viaunshare
) and the overlayfs union filesystem. - atuin - โจ Magical shell history
- fish - the friendly interactive shell
- pure.fish - Pretty, minimal, and fast prompt for Fish shell
Script
- zx - A tool for writing better scripts using javascript
Features
- Fig adds autocomplete to your terminal
- Watchexec - Executes commands in response to file modifications
Reflex
Run a command when files change
I have been using reflex https://github.com/cespare/reflex for the same thing in some of our docker projects
+1 for reflex, love being able to have a config for development
Example .reflex.conf to run one command when an openapi spec changes and another when any go files change:
-g "spec.yaml" -- bash -c 'make'
-sr "\.go$" -- go run cmd/app/main.go
Then run it with:
reflex -d fancy -c .reflex.conf
Why you should use reflex instead
- Reflex has no dependencies. No need to install Ruby or anything like that.
- Reflex uses an appropriate file watching mechanism to watch for changes efficiently on your platform.
- Reflex gives your command the name of the file that changed.
- No DSL to learn -- just give it a shell command.
- No plugins.
- Not tied to any language, framework, workflow, or editor.
Viewer
- fx - Terminal JSON viewer
- Write reducers in your favorite language: JavaScript (default), Python, or Ruby.
์ ๋ Cron์์ ํ์ค ์ถ๋ ฅ์ ์ฌ์ฉํ์ง ๋ง์ธ์ - root ๋ณผ๋ฅจ ํฌํ ๊ดด๋ด
์์นจ์ ๊นจ์ด root disk ์ฌ์ฉ๋ ์๋ฆผ
์ค์ 6์ 40๋ถ, ์ด์ ์๋ฒ ์ค ํ๋์ ๋ฃจํธ ๋์คํฌ ์ฌ์ฉ๋ฅ ์ด 90%๊ฐ ๋๋๋ค๋ ์๋ฆผ์ด ๋ฐ์ํ๋ค. Critical ๋ ๋ฒจ ์๋ฆผ์ด์๊ธฐ ๋๋ฌธ์ ๋ชจ๋ ํ์์๊ฒ ์ ํ๊ฐ ๋ฐ์ ๋๋ค.
์ด ์๋ฒ๋ ๋ชจ๋ํฐ๋ง ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ ์ฉ๋๋ก ์ฌ์ฉํ๋ค. ๋น์ฐํ ๋ชจ๋ ๋ฐ์ดํฐ๋ ๋ณ๋๋ก ๋ง์ดํธํ ๋ฐ์ดํฐ ๋ณผ๋ฅจ์ ์ ์ฅ๋๋ค. ๋ฃจํธ ๋ณผ๋ฅจ์ด ์ด ์ ๋๋ก ๊ฐ๋์ฐจ๋ ๊ฒ์ ์ ์ผ์ด๋์ง ์๋ ์ด์ํ ์ผ์ด๋ค. ๊ฒ๋ค๊ฐ ๋ชจ๋ํฐ๋ง ๋ฐ์ดํฐ๋ฅผ ํ์ธํด๋ณด๋ ํ๋ฃจ๋ง์ ๋์คํฌ ์ฉ๋์ด 5GiB ๊ฐ๋ ์ฆ๊ฐํ๊ณ ์ง๊ธ๋ ๋น ๋ฅธ ์๋๋ก ์ฆ๊ฐํ๊ณ ์์๋ค.
๋์คํฌ ์ฌ์ฉ๋์ด ๋น ๋ฅด๊ฒ ์ฆ๊ฐํ๊ณ ์์์ผ๋ฏ๋ก ์ฐ์ ๋ฃจํธ ๋ณผ๋ฅจ์ ํ์ฅํด ์ฅ์ ๋ฐ์์ ๋ง์๋ค. ๊ทธ๋ฌ๋ ์์ธ์ ๋ฐํ์ง๋ ๋ชปํ๋ค.
์ ๋ น ํ์ผ ์ฌ๊ฑด
/var/log
๋ฑ ๋ฐ์ดํฐ๋ฅผ ๋ง์ด ์ฐจ์งํ ๋งํ ๊ณต๊ฐ์ ํ์ธํด๋ณด์์ผ๋ ํ์ฌ์๋ค. ๊ฒฐ๊ตญ du
๋ช
๋ น์ด๋ก ๋ฃจํธ ๋ณผ๋ฅจ์ ๋ชจ๋ ์๋ธ ๋๋ ํ ๋ฆฌ๋ฅผ ์ ์์กฐ์ฌ ํ์์ง๋ง ๋์คํฌ ์ฌ์ฉ๋์ด ์ฆ๊ฐํ ์์ธ์ ์ฐพ์ ์ ์์๋ค. du ๋ก ํ์ธํ ๋ฃจํธ ๋ณผ๋ฅจ์ ์ฌ์ฉ๋์ 10GB ์ ๋์๋๋ฐ ์ ์ ์๋ 5GB๊ฐ ๋ ์ฌ์ฉ๋๊ณ ์์๋ค.
(์ฐธ๊ณ : du ๋ช ๋ น์ด๋ฅผ ์ฌ๊ท์ ์ผ๋ก ์ฌ์ฉํ๋ ๊ฑด I/O ๋ถํ๊ฐ ์๋นํ๊ธฐ ๋๋ฌธ์ ์ด์ ์๋ฒ์์ ์ํํ๊ธฐ๋ ๋ถ๋ด์ค๋ฌ์ด ์์ ์ด๋ค. nice์ ionice๋ฅผ ์ด์ฉํด ์ฐ์ ์์๋ฅผ ์ตํ๋ก ์ค์ ํ ๋ค ์๋ธ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฐจ์ ์ผ๋ก ํ๋์ฉ ๊ฒ์ฆํ๋ ๋ฑ์ ๋ฐฉ์์ผ๋ก ๋ถํ๋ฅผ ๋ถ์ฐํ์๋ค.)
์ฒ์ ๊ฒ์ฆํ ๊ฐ์ค์ ext4์ ์์ฝ ๊ณต๊ฐ(Reserved space)๊ฐ 5GiB๋ฅผ ์ฌ์ฉํ๋ค๋ ๊ฒ์ด์๋ค. ๊ทธ๋ฌ๋ ์์ฝ ๊ณต๊ฐ์ ์ ์ ์จ์ด ์ ์ฒด ๋์คํฌ ๊ณต๊ฐ์ 5% ๊ฐ๋์ด๊ณ ๋ฃจํธ ๋ณผ๋ฅจ์ ํฌ๊ธฐ๊ฐ 20GB์ ๋ถ๊ณผํ๋ค๋ ์ ์ ๊ฐ์ํ๋ฉด ๊ฐ๋ฅ์ฑ์ด ๊ฑฐ์ ์์๋ค.
๋ค์ ๊ฐ์ค์ ๋ง์ดํธ๋ก ์ธํ ๋ฃจํธ ๋ณผ๋ฅจ ํ์ผ ๋๋ฝ์ด์๋ค. ๋ฃจํธ ๋ณผ๋ฅจ์์ ์ด๋ฏธ ์ฌ์ฉํ๋ ๋๋ ํ ๋ฆฌ์ ๋ค๋ฅธ ๋์คํฌ๋ฅผ ๋ง์ดํธ ํ์ ๋, ๊ธฐ์กด์ ๋๋ ํ ๋ฆฌ์ ์๋ ํ์ผ๋ค์ ์ฌ์ ํ ๋์คํฌ๋ฅผ ์ ์ ํ์ง๋ง du ๊ฒฐ๊ณผ์์๋ ๋ํ๋์ง ์๋๋ค๊ณ ํ๋ค. ๊ทธ๋ฌ๋ ๊ธฐ์กด์ ์ฌ์ฉํ๋ ๋ฐ์ดํฐ ๋ณผ๋ฅจ ์ธ์ ๋ค๋ฅธ ๋์คํฌ๋ฅผ ๋ง์ดํธํ ์ ์ ์์๋ค.
๊ทธ ๋ค์์ผ๋ก ์ญ์ ํ์ผ์ด ๋์คํฌ๋ฅผ ์ ์ ํ๊ณ ์์ ๊ฐ๋ฅ์ฑ์ด๋ค. ๊ธฐ์กด ํ๋ก์ธ์ค๊ฐ ์ด์ด ๋ ํ์ผ์ rm ๋ช ๋ น์ด ๋ฑ์ ์ด์ฉํด ์ญ์ ํ๋๋ผ๋ ๋์คํฌ๋ฅผ ์ ์ ํ๋ค๊ณ ํ๋ค. ํ์ผ์ด ์ญ์ ๋ ์ฌ์ค์ ์์ง ๋ชปํ๋ ํ๋ก์ธ์ค๊ฐ ๋ ์ด์ ์กด์ฌํ์ง ์๋ ํ์ผ์ ๋ด์ฉ์ ์ฝ๋ ๊ฒ์ ๋ฐฉ์งํ๊ธฐ ์ํจ์ด๋ค. ํ๋ก์ธ์ค๊ฐ ํ์ผ์ ๋ซ์์ผ ์์ ํ ๋์คํฌ์์ ์ ๊ฑฐํ๋ค.
๊ทธ๋ผ ํ์ฌ ์คํ๋๋ ํ๋ก์ธ์ค ์ค ์ญ์ ๋ ํ์ผ์ ์ด๊ณ ์๋ ๊ฒ์ด ์๋์ง๋ฅผ ๊ฒ์ฆํ๋ฉด ๋๋ค. ์ฌ์ฉํ ๋ช ๋ น์ด๋ ๋ค์๊ณผ ๊ฐ๋ค.
# nice: CPU ์ฐ์ ์์ ์ตํ๋ก ์ค์
# ionice: I/O ์ฐ์ ์์ ์ตํ๋ก ์ค์
# +L1: ๋งํฌ ์๊ฐ 1๋ณด๋ค ์์ ํ์ผ
nice -n19 ionice -c3 sudo lsof +L1
๊ฒฐ๊ณผ๋ฅผ ํ์ธํด๋ณด๋ rsync๋ฅผ ์ด์ฉํด ํซ ์คํ ๋ฆฌ์ง์์ ์ ์คํ ๋ฆฌ์ง๋ก ํ์ผ์ ์ฎ๊ธฐ๋ cron ํ๋ก์ธ์ค(์ดํ warmer๋ก ํ๊ธฐ)๊ฐ /tmp
๋๋ ํ ๋ฆฌ์ ์ญ์ ๋ ํ์ผ์ ์ด์ด๋๊ณ ์์๋ค. ํฌ๊ธฐ๋ ์ฌ๋ผ์ง 5GB์ ์๋น์ทํ๋ค. ๋์คํฌ ์ฌ์ฉ๋์ด ๊ณ์ ์ฆ๊ฐํ๊ณ ์์์ผ๋ฏ๋ก ํ์ผ์ ํฌ๊ธฐ์ ๋์คํฌ ์ฆ๊ฐ๋์ ๋ฉด๋ฐํ ๋์กฐํด ๋ณผ ์ฌ์ ๋ ์์๋ค. ์ง๊ฐ์ด ๋งํ๋๋๋ก ์ด ํ๋ก์ธ์ค๋ฅผ kill ํ์ ์ฆ์ ๋์คํฌ ์ฌ์ฉ๋์ด ๊ฐ์ํ๋ค.
(์ฐธ๊ณ : ํซ ์คํ ๋ฆฌ์ง๋ ์กฐํ์ ์ฐ๊ธฐ ๋ถํ๊ฐ ์๋์ ์ผ๋ก ๋์, ์ฆ '๋จ๊ฑฐ์ด' ์ ์ฅ์์ด๋ค. ๋ฐ๋ฉด warm ์คํ ๋ฆฌ์ง๋ ๋ถํ๊ฐ ์๋์ ์ผ๋ก ๋ฎ์ '๋ฏธ์ง๊ทผํ' ์ ์ฅ์์ด๋ค. ์ผ๋ฐ์ ์ผ๋ก ์ ์คํ ๋ฆฌ์ง๋ ํซ ์คํ ๋ฆฌ์ง๋ณด๋ค ์ ๋ ดํ ํ์ ์ ์ฌ์ฉํ๋ค. ๋ชจ๋ํฐ๋ง ๋ฐ์ดํฐ๋ ์ต๊ทผ ๋ฐ์ดํฐ์ ์กฐํ ๋น๋๊ฐ ํจ์ฌ ๋๊ธฐ ๋๋ฌธ์ hot/warm ๊ตฌ๋ถ์ ๊ทผ๊ฑฐ๊ฐ ๋ช ํํ๋ค.)
๋ฒ์ธ ๊ฒ๊ฑฐ
warmer๋ฅผ ๋ค์ ์คํํ์ ๋์คํฌ ์ฌ์ฉ๋์ด ๋ค์ ์ฆ๊ฐํ๊ธฐ ์์ํ๋ค. lsof ๊ฒฐ๊ณผ๋ ์ ๊ณผ ์ ์ฌํ๋ค. /tmp
๋๋ ํ ๋ฆฌ์ ์กด์ฌํ์ผ๋ ์ง๊ธ์ ์ญ์ ๋ ํ์ผ์ ์ด์ด๋๊ณ ์๋ค๋ ๊ฒ์ด๋ค. ๋ณด์ ๋ก๊ทธ๋ฅผ ํตํด ๋ชจ๋ ์ฌ์ฉ์์ ๋ช
๋ น์ด๋ฅผ ๊ฒ์ํด๋ณด์์ผ๋ ์ญ์ ๋ช
๋ น์ด๋ฅผ ์ํํ ์ฌ๋์ ์์๋ค. ๊ฒฐ๊ตญ ์ฌ๋์ด ์๋ ํ๋ก์ธ์ค๊ฐ ์ง์ด ๊ฒ์ด ๋ช
ํํ๋ค.
ionotifywait
๋ช
๋ น์ด๋ฅผ ์ด์ฉํด /tmp
๋๋ ํ ๋ฆฌ๋ฅผ ๋ชจ๋ํฐ๋ง ํด๋ณด๋ ํ์คํ ๋ณ๊ฒฝ์ด ์ผ์ด๋๊ณค ์์๋ค. ๊ทธ๋ฌ๋ ์ด ๋ช
๋ น์ด๋ก๋ ์ด๋ค ํ๋ก์ธ์ค๊ฐ ํ์ผ์ ๋ง๋ค๊ณ ์ญ์ ํ๋์ง ์ ์ ์์๋ค.
๋๋ ๋ฒ์ธ์ผ๋ก rsync๋ฅผ ์์ฌํ๋ค. warmer์ ์ฃผ์ ์
๋ฌด๊ฐ rsync๋ฅผ ์คํ์ด์๊ธฐ ๋๋ฌธ์ด๋ค. ์กฐ์ฌ ๊ฒฐ๊ณผ rsync๋ ํ์ผ์ ๋ณต์ฌํ ๋ ์์ ํ์ผ์ ์์ฑํ๋ค๊ณ ํ๋ค. ํ์ ์ ์ป์ ๋๋ ์ํฉ์ ์ฌํํ๊ธฐ ์ํด ์ฌ๋ฌ ํ
์คํธ๋ฅผ ํ๋ค. ๊ทธ๋ฌ๋ ์๋์ ๋ด๊ฐ ํ๋ ธ๋ค๋ ์ฌ์ค์ ์์๋ค๋ ๊ฒ ๋ฟ์ด์๋ค. rsync๋ ์์ ํ์ผ์ /tmp
๊ฐ ์๋๋ผ ๋ชฉ์ ์ง ๋๋ ํ ๋ฆฌ์ ์์ฑํ๋ค. ์์ ํ์ผ์ ์ ์ฅํ ๋๋ ํ ๋ฆฌ๋ฅผ ํ๋๊ทธ๋ก ๋ฐ๋ก ์ง์ ํ๋ฉด ๊ทธ๋ ์ง ์์์๋ ์์ง๋ง, ์ฐ๋ฆฌ๋ ๋ํดํธ ๊ฐ์ ์ฌ์ฉํ๊ณ ์์๋ค.
๊ทธ๋๋ warmer์ ๋ํ ์์ฌ์ ์ ธ๋ฒ๋ฆด ์ ์์๋ ๋๋ /proc
๋๋ ํ ๋ฆฌ์ ์ ๊ทผํด ํ์ผ ๋์คํฌ๋ฆฝํฐ๋ฅผ ์กฐํํ๋ค. ๊ทธ๋ฐ๋ฐ warmer์ 1,2 ๋ฒ ํ์ผ ๋์คํฌ๋ฆฝํฐ๊ฐ /tmp
๋๋ ํ ๋ฆฌ์ ์ญ์ ๋ ํ์ผ์ ์ง์ํ๋ ์ฌ๋ณผ๋ฆญ ๋งํฌ์๋ค.
์ฆ stdout๊ณผ stderr๊ฐ /tmp
๋๋ ํ ๋ฆฌ์ ์ถ๋ ฅ๋๊ณ ์์ผ๋, ํ์ผ์ ๋จ์์์ง ์๊ณ ์ญ์ ๋๊ณ ์์๋ค. ๊ทธ๋ฌ๋ฉด์๋ warmer ๋๋ ํ ๋ฆฌ๊ฐ ๊ทธ ์ญ์ ๋ ํ์ผ์ ๊ณ์ ์ด์ด๋๊ณ ์๋ ์ํฉ์ด์๋ค.
warmer๋ crontab์ผ๋ก ์คํ๋๊ณ ์์๊ณ stdout๊ณผ stderr๋ฅผ ๋ฐ๋ก ๋ฆฌ๋ค์ด๋ ํธํ์ง ์์๋ค. cron์ ํฐ๋ฏธ๋์ ํตํด ์ ์ํ ์ฌ์ฉ์๊ฐ ์๋๋ฏ๋ก ๋ก๊ทธ๋ฅผ ์ฐ์ ๊ณณ์ด ์๊ธด ํ๋ค. ๊ทธ๋ฐ๋ฐ ๋ ๋๋ฐ์ด์ค(/dev/null
)๋ก ์ถ๋ ฅ์ ๋ฒ๋ฆฌ์ง ์๊ณ , '์ถ๋ ฅ์ ์์ ํ์ผ์ ์ ์ฅํ ๋ค ์ญ์ ํ๋ ๋ซ์ง๋ ์๋๋ค.' ๋ผ๋ ์ด์ํ ์ ํ์ ํ ๊ฒ์ด์๋ค.
์ฌํ ํ
์คํธ๋ฅผ ๊ฑฐ์น ๊ฒฐ๊ณผ cron์ด ๋ด๊ฐ ์ถ์ธกํ ๋ฐฉ์๋๋ก ๋์ํ๋ค๋ ๊ฒ์ ํ์ ํ ์ ์์๋ค. ํ์ค ์ถ๋ ฅ์ ๋ฌด์๋ฏธํ ๋ก๊ทธ๋ฅผ ๋จ๊ธฐ๋ shell script๋ฅผ cron์ผ๋ก ์คํํ ๋ค, ์์ ์ด์ผ๊ธฐ ํ lsof
๋ช
๋ น์ด ๊ฒฐ๊ณผ์ /proc
๋๋ ํ ๋ฆฌ์ ํ์ผ ๋์คํฌ๋ฆฝํฐ๋ฅผ ์กฐํํด๋ณด๋ฉด ๋์ผํ ํ์์ด ์ฌํ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
#!/bin/bash
while true; do
head -c $((50 * 1024 * 1024)) < /dev/zero | tr '\0' 'A'
sleep 10
done
(์คํ ํ๊ฒฝ: Ubuntu 24.04)
๋ง์น๋ฉฐ
์์ง๋ cron์ด ์ ํ์ค ์ถ๋ ฅ์ ๋์คํฌ์ ์ ์ฅํ๊ณ ์ถ์ ๊น์ง ์ด๋ ต๊ฒ ๋ง๋๋ ํ๋์ ํ๋์ง ๋ชจ๋ฅด๊ฒ ๋ค. ๊ทธ๋ฌ๋ cron์ ์ง์ ๊ณ ์ณ ์ฐ๊ธฐ๋ ํ์ค์ ์ผ๋ก ์ด๋ ค์ฐ๋ ์ฌ์ฉ๋ฒ์ ๋ฐ๊ฟ์ผ ํ๋ค. ์ฌ์ค cron์ ์คํ ๊ฒฐ๊ณผ๋ฅผ ๋ก๊ทธ๋ก ๋จ๊ธฐ์ง ์๊ณ ๋ฒ๋ฆฌ๋ ๊ฒ์ ์์ ์ ์ฑ๊ณต, ์คํจ ์ฌ๋ถ๋ฅผ ์๊ธฐ ์ด๋ ต๊ฒ ๋ง๋๋ ๋ฐฉ์์ด๋ค. ๊ฒ๋ค๊ฐ ๋๋ฒ๊น ๋ฟ๋ง ์๋๋ผ root ๋์คํฌ ํฌํ๋ฅผ ์ ๋ฐํ ์ ์๋ ์์ฃผ ์ํํ ๋ฐฉ์์์ด ์คํ์ ํตํด ๊ฒ์ฆ๋์๋ค. cron์ ์์ ํ๊ฒ ์ํํ๋ ค๋ฉด ๋ค์์ ๋ฐฉ์นจ์ ๋ฐ๋ผ์ผ ํ๋ค.
- ํ์ผ์ ๋ก๊ทธ๋ฅผ ๋จ๊ธด๋ค.
- ๋ก๊ทธ ํ์ผ์ ๋ฃจํธ ๋ณผ๋ฅจ์ด ์๋๋ผ ๋ฐ์ดํฐ ๋ณผ๋ฅจ์ ์์น์์ผ์ผ ํ๋ค
- logrotate ๋ฑ์ ์๋จ์ ์ด์ฉํด ํฌ๊ธฐ๊ฐ ๋ฌดํ์ ์ปค์ง์ง ์๋๋ก ์ ์ดํด์ผ ํ๋ค.
Children