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.