0%

Linux commands

Most commonly used Linux commands

Git

Local files -> Local Git Repo

1
2
3
4
cd project_folder
git init
git add . (git add aFile)
git commit -m "Initial commit"

Local Git Repo -> Remote Git Fork

1
2
3
git remote add origin git@github.com:xxx/xxx.git
(git remote rm origin)
git push -u origin master.

Update commit changes

1
2
3
4
git status
git add .
git commit -m "xxx"
git push -u origin master

Remote Git Fork -> Local Git Repo

1
git pull origin master

Branch

1
2
git branch new_branch
git checkout -b new_branch

Merge Branch

1
2
git checkout branch_1
git merge branch_2

Show All Branches

1
git branch -a

Kill process

1
2
lsof -i:Port
Kill -9 PID

Script:

1
2
3
4
5
6
7
#!/bin/bash
lsof -i :4000 | awk '{print $2}'> tmp
pid=$(awk 'NR==2{print}' tmp);
# kill process if its PID exists
if [ -n "$pid" ]; then
kill -9 $pid;
fi

What is my IP Address?

1
curl https://ipinfo.io/ip

Download and Upload

1
2
3
4
5
6
Remote => Local: 
scp -P port remoteuser@ip:file_path local_path
Local => Remote:
scp /path/to/local/file username@hostname:/path/to/remote/file
Remote => Remote
scp username1@hostname1:/path/to/file username2@hostname2:/path/to/other/file

Compress and Extract

1
2
tar -zcvf xxx
tar xvzf file.tar.gz

See more

Vim Editor

  • : 进入命令模式
  • wq 保存&退出
  • / 查找模式
  • i 插入模式(插入结束Esc)

Copy and Paste

1
2
copy the whole file :%w !pbcopy
past from the clipboard :r !pbpaste

Delete lines

Delete lines

More

Cheat Sheet
Vim Tutorial

More

https://juejin.im/post/5d6cb968e51d4561e721df3c