Cheatsheet for Common Usage CLI

January 2, 2019
Tools DevOps

Curl Post JSON

curl -i -d '{"id": "111111","date": "2018-04-27T00:00:00+10:00","des": "test"}]' -H "Content-Type: application/json" -X POST https://endpoint

curl -i -d '{"a":"1","b":"2"}' -H "Content-Type: application/json" -X POST https://endpoint

Database

MySQL

SHOW VARIABLES;

SELECT FROM_UNIXTIME(1510289234);

SELECT NOW();

SELECT UNIX_TIMESTAMP();

MongoDB

mongod --dbpath ~/data/mongodb

PostgreSQL

pg_dump --dbname=postgresql://user:admin@127.0.0.1:5432/database-name --table=my-table --data-only --column-inserts > data.sql

Zip / tar

zip filename.zip file1 file2
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
  • -c: Create an archive.
  • -z: Compress the archive with gzip.
  • -v: Display progress in the terminal while creating the archive, also known as “verbose” mode. The v is always optional in these commands, but it’s helpful.
  • -f: Allows you to specify the filename of the archive.
tar -xzvf archive.tar.gz

cp

rsync -av --progress /Users/kcsun/github/uiux/sourcefoder/ ./ --exclude .git

SSH / scp

// setup tunel
ssh -L 8002:target-host-ip:80 -i ~/.ssh/ssh-key hostname@host-ip

// from local to remote
scp /filename hostname@ip:~

// from remote to local
scp -i ~/.ssh/ssh-key root@host:~/hello ./

Docker

// docker download file
docker cp <containerId>:/file/path/within/container /host/path/target

// show sha256
docker inspect --format='{{index .RepoDigests 0}}' $IMAGE

Journalctl

// Display kernal message:
journalctl -k | grep -i -e memory -e oom

Generate table of contents for markdown

gh-md-toc README.md

Calculate lines of code in project

find . -name '*.scala' | xargs wc -l

Docker override entrypoint

docker run -it --entrypoint /usr/bin/redis-cli example/redis

Git

Reset local branch after force push:

git reset origin/master --hard

Rebase to certain commit, like change commit msg:

git rebase -i commit-id // p to pick, r to change msg

Rebase to origin after squashed merge

git rebase -i origin/main

** Delete branch with illegal name:**

git branch -D -- --track

When branch and tag use a same name:

git push origin refs/heads/v2.0.0:refs/heads/v2.0.0

Submodule

To remove a submodule

https://gist.github.com/myusuf3/7f645819ded92bda6677

git submodule status

Nodejs npm mirror

npm config set registry=http://registry.npm.taobao.org

Rust and Cargo

Source

Configiure china source, modify the file $HOME/.cargo/config

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

cargo expand

https://github.com/dtolnay/cargo-expand

comments powered by Disqus