mac终端机命令
Youga 8/19/2017 终端机Linux常用命令
# 云主机日常使用命令
# 连接主机
ssh -i ~/.ssh/ssh_key root@ip
# 退出云主机
exit 或 logout (退出云主机)
# 查看使用的端口号
netstat -ntlp (linux)
lsof -n -P -i TCP -s TCP:LISTEN (mac)
lsof -i:8080
# 结束进程
Kill pid(进程id) (解决端口号被程序占用)
# 工具安装目录查询
which node
# 主机立刻重启
reboot
shutdown -r now 立刻重启(root用户使用)
# linux 开机自动启动文件:
/etc/rc.local
(注意chmod +x /etc/rc.d/rc.local)
开机启动文件夹
(~/ /System /)
/Library/PreferencePanes
/Library/Preferences
/Library/LaunchAgents
# linux 安装 git
git/: .config prefix=/usr/local/bin/git
make
make install
# mongodb 启动
./mongod --dbpath=/data/db --rest
# 开机启动 mongodb
echo "/usr/local/mongodb/bin/mongod --dbpath=/data/db" >> /etc/rc.local
重启远程计算机即可
# 安装目录添加到全局
export PATH=/(安装工具到bin目录):$PATH (关闭终端失效)
ln -s /usr/download/bin /usr/local/bin (链接 -s 软链接 相当于只创建快捷方式)
# 命令行下载
wget https://download.zip
curl -0 https://download.zip
# mac 日常使用命令
# 修改 mac 计算机名称
scutill —set / —get LocalHostName / ComputerName / HostName name
# 启动 chrome 跨域
open -a "Google Chrome" --args --disable-web-security --user-data-dir
open -a "Google Chrome" --args --disable-web-security
open -a "Opera" --args --disable-web-security --user-data-dir
open -a "QQBrowser" --args --disable-web-security --user-data-dir
open -n /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=/Users/someFolder
# linux 开机自动启动文件:
macOS系统的启动项会以 .plist 的文件存在于以下目录中
/Library/LaunchDaemons:系统启动时运行,用户不登录也会运行。
/Library/LaunchAgents:用户登录后运行。
~/Library/LaunchAgents:用户自定义的用户启动项
/System/Library/LaunchDaemons:系统自带的启动项
/System/Library/LaunchAgents:系统自带的启动项
# 本地 https 测试
(安装 ngrok)
ngrok http localhost:8000
ngrok http 192.168.1.1:8000
# npm 本地私包
npm i -g verdaccio (安装管理工具)
verdaccio —listen 8080
pm2 start verdaccio (关闭命令行运行)
npm set registry http://location:8080/ (修改源)
npm adduser (name 随意)
(公共组建A根目录) npm publish (提交到私服)
npm I A
# 终端机编译 C
gcc ./path/name.c -o outname
# 文件目录管理
# 拷贝
cp path1 path2
# 移动修改
mv path1 path2
# 删除
rm -r path1 (-r 文件夹)
rm -rf path1 (-f 强制删除)
# 创建目录
mkdir path
mkdir -p path1/path2 (没有path1 -p 自动创建)
# 权限管理
sudo chmod 777
三位数字分别代表
user、group、others 的权限,
可读(r)、可写(w)、可执行(x)的权限分别用数字 4、2、1 表示,
数字7是权限 4、2、1 的和,
777 即代表 user、group、others 均具有可读(r)、可写(w)、可执行(x)的权限,为最高权限。
# 压缩包解压
tar -zxvf download.gz
tar -xvf .xz
unzip filename.zip
# 文件压缩
zip xx.zip ./*
# 远程拷贝
scp 云主机 / 本地 文件拷贝
scp -i ~/.ssh/id_rsa(ssh-key) -r(文件夹) ./path(路径) username@ip:/path
# 批量重命名:
rename 's/old/new/' *.files
# Git 常用命令
# Git 切换远程分支
git remote remove {name=origin}
git remote add {name}
git push -u origin master
# git 回滚
git reset --hard (commitId) (删除 commit 记录)
git checkout (commitId) ./file (保留原来 commit 记录)
# git url 带上用户名密码
git clone http://user:password@git.xx.com/
git https 记住用户名密码 (ssh key 对https 无效)
git config —global credendial.helper store
# 更新本地分支缓存
git fetch -p