目录
项目初始化与管理
创建新项目
npx create-react-app my-app
npx create-react-app my-app --template typescript
npm create vue@latest my-vue-project
vue create my-project
npx create-next-app@latest my-next-app
npx create-next-app@latest my-next-app --typescript
npm create vite@latest my-vite-app
yarn create vite my-vite-app
ng new my-angular-app
npm init
npm init -y
项目脚手架工具
npm install -g yo
yo webapp
npx degit user/repo my-project
包管理器命令
NPM命令
npm install
npm install package-name
npm install -g package-name
npm install --save-dev package
npm install --save-exact package
npm uninstall package-name
npm uninstall -g package-name
npm update
npm update package-name
npm outdated
npm list
npm list -g --depth=0
npm info package-name
npm view package-name versions
npm cache clean --force
npm cache verify
npm run script-name
npm run
Yarn命令
yarn
yarn add package-name
yarn add -D package-name
yarn global add package-name
yarn remove package-name
yarn global remove package-name
yarn upgrade
yarn upgrade package-name
yarn list
yarn info package-name
yarn outdated
yarn cache clean
yarn script-name
PNPM命令
pnpm install
pnpm add package-name
pnpm add -D package-name
pnpm add -g package-name
pnpm remove package-name
pnpm remove -g package-name
pnpm update
pnpm outdated
pnpm run script-name
开发服务器与构建
开发服务器
npm start
npm run dev
yarn start
yarn dev
pnpm dev
PORT=3001 npm start
npm start -- --port 3001
npm run build
yarn build
pnpm build
npm run preview
yarn preview
pnpm preview
Webpack相关
npx webpack serve
npx webpack serve --mode development
npx webpack serve --open
npx webpack
npx webpack --mode production
npx webpack --watch
Git版本控制
基础操作
git init
git clone <repository-url>
git clone <repository-url> <directory-name>
git status
git status -s
git add .
git add file-name
git add *.js
git commit -m "commit message"
git commit -am "commit message"
git log
git log --oneline
git log --graph
分支操作
git branch
git branch -r
git branch -a
git branch branch-name
git checkout -b branch-name
git switch -c branch-name
git checkout branch-name
git switch branch-name
git merge branch-name
git merge --no-ff branch-name
git branch -d branch-name
git branch -D branch-name
远程操作
git remote -v
git remote add origin <repository-url>
git push origin main
git push -u origin main
git pull origin main
git fetch origin
git tag v1.0.0
git push origin --tags
文件操作
基础文件操作
ls
ls -la
ls -lh
touch filename
mkdir dirname
mkdir -p path/to/dirname
cp source destination
cp -r source destination
mv source destination
rm filename
rm -rf dirname
rm -i filename
cat filename
head filename
tail filename
tail -f filename
less filename
文件查找
find . -name "*.js"
find . -type f -name "*.css"
find . -type d -name "node_modules"
grep "search-text" filename
grep -r "search-text" .
grep -i "search-text" filename
进程管理
查看进程
ps aux
ps aux | grep node
top
htop
lsof -i :3000
netstat -tulpn | grep :3000
进程控制
kill PID
kill -9 PID
killall node
nohup npm start &
npm start &
pm2 start app.js
pm2 list
pm2 stop app
pm2 restart app
网络与调试
网络请求
curl https://api.example.com
curl -X POST -d "data" url
curl -H "Content-Type: application/json" -d '{"key":"value"}' url
wget https://example.com/file.zip
ping google.com
telnet localhost 3000
调试工具
netstat -an
ss -tulpn
tail -f /var/log/nginx/access.log
journalctl -f
iostat
vmstat
代码质量与测试
代码检查
npx eslint .
npx eslint --fix .
npx eslint --init
npx prettier --write .
npx prettier --check .
npx tsc
npx tsc --noEmit
测试命令
npm test
npm test -- --watch
npm test -- --coverage
npx mocha
npx cypress open
npx playwright test
部署相关
构建与部署
npm run build
yarn build
npx serve -s build
npx http-server dist
docker build -t app-name .
docker run -p 3000:3000 app-name
scp -r build/ user@server:/path
rsync -av build/ user@server:/path
环境变量
export NODE_ENV=production
export API_URL=https://api.example.com
echo "API_URL=https://api.example.com" > .env
系统信息查看
系统状态
uname -a
whoami
pwd
date
df -h
du -sh *
du -sh node_modules
free -h
vm_stat
环境信息
node --version
npm --version
npx --version
npm list -g --depth=0
yarn global list
env
echo $PATH
echo $NODE_ENV
实用技巧
命令组合
npm install && npm start
npm run build && npm run deploy
ps aux | grep node
ls -la | grep "\.js$"
npm test || echo "Tests failed"
快捷操作
history
!!
!n
cd -
pushd /path && popd
code .
vim filename
别名设置
alias ll='ls -la'
alias la='ls -la'
alias ..='cd ..'
alias ...='cd ../..'
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git pull'
alias nrs='npm run start'
alias nrb='npm run build'
alias nrt='npm run test'
注意事项
- 权限问题: 某些命令可能需要管理员权限,使用
sudo 前缀
- 路径问题: 注意相对路径和绝对路径的区别
- 版本兼容: 不同版本的工具命令可能有差异
- 备份重要: 删除操作前请确保重要文件已备份
- 环境差异: Windows、macOS、Linux系统间命令可能有差异
推荐学习资源