Engineering Tools for AI

程式設計

常用終端機指令

整理編輯、執行、測試與除錯 Web 專案時常用的終端機指令。

33 個指令

導覽

print working directory

pwd

pwd

意思

Prints the absolute path of the folder where the terminal is currently working.

使用時機

Run it before commands that depend on being inside the project folder.

範例

pwd

請求範例

Check which folder the terminal is currently in.

導覽

list files

ls

ls

意思

Lists files and folders in the current directory.

使用時機

Use it to confirm expected files such as package.json, src, or next.config.mjs are present.

範例

ls

請求範例

List the files in the current project folder.

導覽

change directory

cd

cd ~/projects/my-web-app

意思

Moves the terminal to another folder.

使用時機

Use it before running project-specific commands such as npm run build.

注意

A command can fail if you are in the wrong folder, even when the command itself is correct.

範例

cd ~/projects/my-web-app

請求範例

Move to the project folder before running commands.

導覽

clear screen

clear

clear

意思

Clears visible terminal output without changing files or command history.

使用時機

Use it before rerunning a command when the old output is visually noisy.

範例

clear

請求範例

Clear the terminal before rerunning the build.

檔案與資料夾

show file contents

cat

cat package.json

意思

Prints the contents of a file to the terminal.

使用時機

Use it for short files such as package.json, config files, or small text files.

注意

For very large files, prefer sed, rg, or a pager instead of printing everything.

範例

cat package.json

請求範例

Show the package.json scripts.

檔案與資料夾

show selected lines

sed

sed -n '1,120p' src/components/SiteHeader.tsx

意思

Can print a selected range of lines from a file.

使用時機

Use it to inspect one section of a source file without opening the whole file.

範例

sed -n '1,120p' src/components/SiteHeader.tsx

請求範例

Show the first 120 lines of SiteHeader.tsx.

檔案與資料夾

make directory

mkdir

mkdir -p src/app/[locale]/reference/terminal-commands

意思

Creates a new folder. The -p option also creates missing parent folders and avoids failing if the folder already exists.

使用時機

Use it before adding a new page folder or asset folder.

範例

mkdir -p src/app/[locale]/reference/terminal-commands

請求範例

Create the route folder for the terminal commands page.

檔案與資料夾

copy files

cp

cp .env.example .env.local

意思

Copies a file or folder to another location.

使用時機

Use it to create local config from an example file or duplicate a template.

注意

If the destination file exists, cp can overwrite it.

範例

cp .env.example .env.local

請求範例

Copy the example env file only if it will not overwrite local settings.

檔案與資料夾

move or rename

mv

mv old-name.ts new-name.ts

意思

Moves a file or folder, or renames it when the destination is in the same folder.

使用時機

Use it when changing a filename, route folder name, or moving assets.

注意

Renaming route folders changes URLs.

範例

mv old-name.ts new-name.ts

請求範例

Rename this file and update imports if needed.

安全操作

remove files

rm

rm unused-file.ts

意思

Deletes files. With -r it can delete folders recursively.

使用時機

Use it only when a file is intentionally removed from the project.

注意

rm is destructive. Check the path carefully before running it.

範例

rm unused-file.ts

請求範例

Before deleting this file, explain what will be removed.

搜尋與檢查

ripgrep search

rg

rg -n "errorMessageGuide" src

意思

Searches text quickly across files.

使用時機

Use it to find imports, components, slugs, CSS classes, or old names before editing.

範例

rg -n "errorMessageGuide" src

請求範例

Search where this component is imported.

搜尋與檢查

list tracked-looking files fast

rg --files

rg --files src/app

意思

Lists file paths quickly, respecting common ignore rules.

使用時機

Use it to find page files, components, and libraries without scanning build output.

範例

rg --files src/app

請求範例

List reference page files under src/app.

搜尋與檢查

find paths

find

find src -name 'page.tsx'

意思

Searches the filesystem by path, name, or other file properties.

使用時機

Use it when searching by filename pattern rather than text content.

範例

find src -name 'page.tsx'

請求範例

Find every page.tsx route file.

搜尋與檢查

count lines or words

wc

wc -l src/lib/terminal-commands.ts

意思

Counts lines, words, or bytes.

使用時機

Use it to estimate file size or count search results when combined with other commands.

範例

wc -l src/lib/terminal-commands.ts

請求範例

Count how many lines are in this data file.

套件

install dependencies

npm install

npm install

意思

Installs packages listed in package.json and package-lock.json.

使用時機

Use it after cloning a project or when dependencies are missing.

注意

It can change package-lock.json if dependency versions resolve differently.

範例

npm install

請求範例

Install dependencies only if node_modules is missing.

開發伺服器

start dev server

npm run dev

npm run dev

意思

Runs the project's local development server script.

使用時機

Use it to test pages in the browser while editing.

注意

A running dev server keeps the terminal session busy until stopped.

範例

npm run dev

請求範例

Start the dev server and tell me the local URL.

套件

production build

npm run build

npm run build

意思

Runs the production build script and catches many compile, route, and type problems.

使用時機

Run it before deployment or after adding new pages.

範例

npm run build

請求範例

Run the production build and summarize warnings or failures.

套件

lint check

npm run lint

npm run lint

意思

Runs the project's lint script to catch style and static code issues.

使用時機

Run it before build when you want quick feedback.

範例

npm run lint

請求範例

Run lint and show only actionable errors.

套件

check Node version

node -v

node -v

意思

Prints the installed Node.js version.

使用時機

Use it when a project or dependency requires a specific Node version.

範例

node -v

請求範例

Check the Node.js version before explaining this warning.

套件

run package command

npx

npx next info

意思

Runs a command from an installed or temporarily downloaded npm package.

使用時機

Use it for one-off tooling commands when no package script exists.

注意

npx can download packages from the network if they are not installed.

範例

npx next info

請求範例

Explain whether this npx command needs network access.

Git

check Git status

git status

git status --short

意思

Shows the current branch and changed, staged, or untracked files.

使用時機

Run it before edits, commits, pulls, or branch switches.

範例

git status --short

請求範例

Check Git status and summarize the changed files.

Git

show code differences

git diff

git diff -- src/components/SiteHeader.tsx

意思

Shows line-by-line differences in changed files.

使用時機

Use it to review exactly what changed before committing.

範例

git diff -- src/components/SiteHeader.tsx

請求範例

Review the diff for this task.

Git

view commit history

git log

git log --oneline -5

意思

Shows commit history.

使用時機

Use it to see recent work or find a commit to inspect.

範例

git log --oneline -5

請求範例

Show the five most recent commits.

Git

stage changes

git add

git add src/lib/terminal-commands.ts

意思

Selects changes to include in the next commit.

使用時機

Use explicit paths for focused commits.

範例

git add src/lib/terminal-commands.ts

請求範例

Stage only files related to this terminal commands page.

Git

save commit

git commit

git commit -m "Add terminal command reference"

意思

Records staged changes into Git history.

使用時機

Use it after reviewing the staged changes.

範例

git commit -m "Add terminal command reference"

請求範例

Commit the staged changes with a clear message.

開發伺服器

stop running command

Ctrl+C

Press Ctrl+C in the dev server terminal

意思

Interrupts the currently running terminal command.

使用時機

Use it to stop a local dev server before closing the terminal or changing ports.

注意

Use it in the terminal session where the command is running.

範例

Press Ctrl+C in the dev server terminal

請求範例

Stop the running dev server.

開發伺服器

list open files and ports

lsof

lsof -i :3001

意思

Can show which process is using a port.

使用時機

Use it when a dev server fails with EADDRINUSE.

範例

lsof -i :3001

請求範例

Find which process is using port 3001.

開發伺服器

list processes

ps

ps aux

意思

Shows running processes.

使用時機

Use it to inspect running development tools, servers, or background processes.

範例

ps aux

請求範例

Check whether a Next.js dev server is still running.

安全操作

stop process by PID

kill

kill 12345

意思

Sends a signal to stop a process by process ID.

使用時機

Use it when a server keeps running after normal interruption is not available.

注意

Check the PID carefully so you do not stop the wrong process.

範例

kill 12345

請求範例

Before killing a process, show me what the PID belongs to.

網路

make HTTP request

curl

curl -I http://localhost:3001/ko

意思

Sends HTTP requests from the terminal and prints the response.

使用時機

Use it to check whether a local or deployed URL returns 200, 404, 500, or redirects.

範例

curl -I http://localhost:3001/ko

請求範例

Use curl to check whether this page returns 200.

網路

check network reachability

ping

ping 172.30.1.55

意思

Checks whether a host responds to basic network packets.

使用時機

Use it as a rough network reachability check, not as a web app health check.

範例

ping 172.30.1.55

請求範例

Check whether this device can reach the dev machine IP.

搜尋與檢查

locate command executable

which

which node

意思

Shows which executable file will run for a command name.

使用時機

Use it when different Node, npm, or tool versions may exist on the machine.

範例

which node

請求範例

Check which node executable is being used.

安全操作

change file permissions

chmod

chmod +x script.sh

意思

Changes read, write, or execute permissions on files.

使用時機

Use it when a local script should be executable.

注意

Avoid broad permission changes such as chmod -R 777.

範例

chmod +x script.sh

請求範例

Explain the safest permission change for this script.