Engineering Tools for AI

Lập trình

Lệnh terminal quan trọng

Hướng dẫn tra cứu các lệnh terminal thường dùng khi sửa, chạy, kiểm thử và debug dự án web.

33 lệnh

Điều hướng

print working directory

pwd

pwd

Ý nghĩa

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

Khi dùng

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

Ví dụ

pwd

Ví dụ yêu cầu

Check which folder the terminal is currently in.

Điều hướng

list files

ls

ls

Ý nghĩa

Lists files and folders in the current directory.

Khi dùng

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

Ví dụ

ls

Ví dụ yêu cầu

List the files in the current project folder.

Điều hướng

change directory

cd

cd ~/projects/my-web-app

Ý nghĩa

Moves the terminal to another folder.

Khi dùng

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

Lưu ý

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

Ví dụ

cd ~/projects/my-web-app

Ví dụ yêu cầu

Move to the project folder before running commands.

Điều hướng

clear screen

clear

clear

Ý nghĩa

Clears visible terminal output without changing files or command history.

Khi dùng

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

Ví dụ

clear

Ví dụ yêu cầu

Clear the terminal before rerunning the build.

Tệp và thư mục

show file contents

cat

cat package.json

Ý nghĩa

Prints the contents of a file to the terminal.

Khi dùng

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

Lưu ý

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

Ví dụ

cat package.json

Ví dụ yêu cầu

Show the package.json scripts.

Tệp và thư mục

show selected lines

sed

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

Ý nghĩa

Can print a selected range of lines from a file.

Khi dùng

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

Ví dụ

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

Ví dụ yêu cầu

Show the first 120 lines of SiteHeader.tsx.

Tệp và thư mục

make directory

mkdir

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

Ý nghĩa

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

Khi dùng

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

Ví dụ

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

Ví dụ yêu cầu

Create the route folder for the terminal commands page.

Tệp và thư mục

copy files

cp

cp .env.example .env.local

Ý nghĩa

Copies a file or folder to another location.

Khi dùng

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

Lưu ý

If the destination file exists, cp can overwrite it.

Ví dụ

cp .env.example .env.local

Ví dụ yêu cầu

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

Tệp và thư mục

move or rename

mv

mv old-name.ts new-name.ts

Ý nghĩa

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

Khi dùng

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

Lưu ý

Renaming route folders changes URLs.

Ví dụ

mv old-name.ts new-name.ts

Ví dụ yêu cầu

Rename this file and update imports if needed.

An toàn

remove files

rm

rm unused-file.ts

Ý nghĩa

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

Khi dùng

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

Lưu ý

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

Ví dụ

rm unused-file.ts

Ví dụ yêu cầu

Before deleting this file, explain what will be removed.

Tìm kiếm và kiểm tra

ripgrep search

rg

rg -n "errorMessageGuide" src

Ý nghĩa

Searches text quickly across files.

Khi dùng

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

Ví dụ

rg -n "errorMessageGuide" src

Ví dụ yêu cầu

Search where this component is imported.

Tìm kiếm và kiểm tra

list tracked-looking files fast

rg --files

rg --files src/app

Ý nghĩa

Lists file paths quickly, respecting common ignore rules.

Khi dùng

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

Ví dụ

rg --files src/app

Ví dụ yêu cầu

List reference page files under src/app.

Tìm kiếm và kiểm tra

find paths

find

find src -name 'page.tsx'

Ý nghĩa

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

Khi dùng

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

Ví dụ

find src -name 'page.tsx'

Ví dụ yêu cầu

Find every page.tsx route file.

Tìm kiếm và kiểm tra

count lines or words

wc

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

Ý nghĩa

Counts lines, words, or bytes.

Khi dùng

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

Ví dụ

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

Ví dụ yêu cầu

Count how many lines are in this data file.

Gói

install dependencies

npm install

npm install

Ý nghĩa

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

Khi dùng

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

Lưu ý

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

Ví dụ

npm install

Ví dụ yêu cầu

Install dependencies only if node_modules is missing.

Dev server

start dev server

npm run dev

npm run dev

Ý nghĩa

Runs the project's local development server script.

Khi dùng

Use it to test pages in the browser while editing.

Lưu ý

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

Ví dụ

npm run dev

Ví dụ yêu cầu

Start the dev server and tell me the local URL.

Gói

production build

npm run build

npm run build

Ý nghĩa

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

Khi dùng

Run it before deployment or after adding new pages.

Ví dụ

npm run build

Ví dụ yêu cầu

Run the production build and summarize warnings or failures.

Gói

lint check

npm run lint

npm run lint

Ý nghĩa

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

Khi dùng

Run it before build when you want quick feedback.

Ví dụ

npm run lint

Ví dụ yêu cầu

Run lint and show only actionable errors.

Gói

check Node version

node -v

node -v

Ý nghĩa

Prints the installed Node.js version.

Khi dùng

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

Ví dụ

node -v

Ví dụ yêu cầu

Check the Node.js version before explaining this warning.

Gói

run package command

npx

npx next info

Ý nghĩa

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

Khi dùng

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

Lưu ý

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

Ví dụ

npx next info

Ví dụ yêu cầu

Explain whether this npx command needs network access.

Git

check Git status

git status

git status --short

Ý nghĩa

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

Khi dùng

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

Ví dụ

git status --short

Ví dụ yêu cầu

Check Git status and summarize the changed files.

Git

show code differences

git diff

git diff -- src/components/SiteHeader.tsx

Ý nghĩa

Shows line-by-line differences in changed files.

Khi dùng

Use it to review exactly what changed before committing.

Ví dụ

git diff -- src/components/SiteHeader.tsx

Ví dụ yêu cầu

Review the diff for this task.

Git

view commit history

git log

git log --oneline -5

Ý nghĩa

Shows commit history.

Khi dùng

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

Ví dụ

git log --oneline -5

Ví dụ yêu cầu

Show the five most recent commits.

Git

stage changes

git add

git add src/lib/terminal-commands.ts

Ý nghĩa

Selects changes to include in the next commit.

Khi dùng

Use explicit paths for focused commits.

Ví dụ

git add src/lib/terminal-commands.ts

Ví dụ yêu cầu

Stage only files related to this terminal commands page.

Git

save commit

git commit

git commit -m "Add terminal command reference"

Ý nghĩa

Records staged changes into Git history.

Khi dùng

Use it after reviewing the staged changes.

Ví dụ

git commit -m "Add terminal command reference"

Ví dụ yêu cầu

Commit the staged changes with a clear message.

Dev server

stop running command

Ctrl+C

Press Ctrl+C in the dev server terminal

Ý nghĩa

Interrupts the currently running terminal command.

Khi dùng

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

Lưu ý

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

Ví dụ

Press Ctrl+C in the dev server terminal

Ví dụ yêu cầu

Stop the running dev server.

Dev server

list open files and ports

lsof

lsof -i :3001

Ý nghĩa

Can show which process is using a port.

Khi dùng

Use it when a dev server fails with EADDRINUSE.

Ví dụ

lsof -i :3001

Ví dụ yêu cầu

Find which process is using port 3001.

Dev server

list processes

ps

ps aux

Ý nghĩa

Shows running processes.

Khi dùng

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

Ví dụ

ps aux

Ví dụ yêu cầu

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

An toàn

stop process by PID

kill

kill 12345

Ý nghĩa

Sends a signal to stop a process by process ID.

Khi dùng

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

Lưu ý

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

Ví dụ

kill 12345

Ví dụ yêu cầu

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

Mạng

make HTTP request

curl

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

Ý nghĩa

Sends HTTP requests from the terminal and prints the response.

Khi dùng

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

Ví dụ

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

Ví dụ yêu cầu

Use curl to check whether this page returns 200.

Mạng

check network reachability

ping

ping 172.30.1.55

Ý nghĩa

Checks whether a host responds to basic network packets.

Khi dùng

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

Ví dụ

ping 172.30.1.55

Ví dụ yêu cầu

Check whether this device can reach the dev machine IP.

Tìm kiếm và kiểm tra

locate command executable

which

which node

Ý nghĩa

Shows which executable file will run for a command name.

Khi dùng

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

Ví dụ

which node

Ví dụ yêu cầu

Check which node executable is being used.

An toàn

change file permissions

chmod

chmod +x script.sh

Ý nghĩa

Changes read, write, or execute permissions on files.

Khi dùng

Use it when a local script should be executable.

Lưu ý

Avoid broad permission changes such as chmod -R 777.

Ví dụ

chmod +x script.sh

Ví dụ yêu cầu

Explain the safest permission change for this script.