finas / note

日常tips

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

linux:

  1. openssl passwd -crypt 12345 will generate different output every time but how to check the 12345 send from client whether is same as the server.
  2. xargs convert stdout to args ls |xargs echo
  3. press c-v in vim enter visual block then do the multi select
  4. linux redirect link1,link2,link3,link4
  5. use who ,last to get all logined user
  6. curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python - for testing network speed
  7. man -k or apropos
  8. tail -n 20 /var/log/nginx/error.log to find nginx problem.
  9. cat ~/.ssh/id_rsa.pub | ssh username@hostname ' mkdir -p .ssh && cat >>.ssh/authorized_keys' copy public key to server authorized_key.
  10. sudo chown -R group:user folder change the folder user group.
  11. docker update --restart=no my-container to update the running container flag
  12. grep --color -R --exclude-dir=node_modules '\.js"\ to find
  13. curl -v -H "Accept: application/json" https://httpbin.org/get will see the request header and body
  14. curl -s -I -v http://www.baidu.com simple get request and response header
  15. find / -type d -name "*Chrome.app" find chrome
  16. npm-check -u to check npm package health
  17. curl http://www.vdberg.org/~richard/tcpping -o tcpping to download tcpping
  18. cat foo.c | sed '/^\s*#/d;/^\s*$/d' | wc -l to count-non-blank-lines-of-code-in-bash
  19. stty -ixon to enable XON/XOFF flow control then you can use ctrl-s to reverse-reverse-i-search
  20. find . -type f -name '*.gz' -exec rm {} + to remove all file type endwith gz
  21. curl cli.fyi/help
  22. a++ is unary
  23. setw -g mode-keys vi for tmux
  24. export http_proxy='http://proxyServerSddress:proxyPort' finally unset http_proxy
  25. echo 050100 | xxd -p -r | netcat -o out.txt {server} {port} test socks5 proxy
  26. socat tcp-l:7654,fork,reuseaddr tcp:27.122.57.247:7654 & socat UDP-LISTEN:7654,fork,reuseaddr dup:27.122.57.247:7654 & for port forward
  27. cp /home/sample.txt{,-old} =>cp /home/sample.txt /home/sample.txt-oldx
  28. apropos "list directory" to recall command
  29. curl -o /dev/null -s -w 'Establish Connection: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n' https://www.google.com
  30. mtr='PATH=/usr/local/sbin:$PATH sudo mtr' export PATH=/opt/local/bin:/usr/local/Cellar/mtr/0.92/sbin/:$PATH enable mtr at mac..
  31. who | grep -v 'via mosh' | grep -oP '(?<=mosh \[)(\d+)(?=\])' | xargs kill or kill pidof mosh-server kill the mosh session belong to you
  32. ps aux | grep "[f]nord" or ps aux | grep -v grep | grep "fnord" or
  33. less -r output.txt to view termnial-style txt
  34. sudo du -a / 2>/dev/null | sort -n -r | head -n 20 find big files
  35. iptables-save |vi - to check the rule script
  36. iptables -A INPUT -s 192.168.1.100 -p icmp -j DROP or iptables -A INPUT -p icmp -j DROP
  37. wireshark -k -i <( ssh -l root IP-of-probe /usr/bin/tshark -i eth0 -w - port 53 ) capture remote ssh network package
  38. find -type f -print0 2>/dev/null | xargs -0 -n 10 grep -i searchstring 2>/dev/null Redirect standard error to /dev/null
  39. du -h -d 1 | sort -hr see folder size
  40. sh -x script [arg1 ...] bash -x script [arg1 ...] set -x set +x debug script
  41. you need confirm your .ssh folder is accessible by user(you will get a key failed auth). chown -r owner-user:owner-group .ssh for change to file owner
  42. replace str grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/g' in OSX sed -i "" 's/str1/str2/g'
  43. cat 0021500492.json | python -m json.tool |less for view large json file.
  44. sudo add-apt-repository universe then sudo apt-get install netcat-traditional then sudo update-alternatives --config nc finally Select the option /bin/nc.traditional
  45. curl -s -v -X HEAD http://foo.com/bar/baz.pdf 2>&1 | grep '^< Last-Modified:' for query website upgrade time
  46. socat tcp-l:4431,fork,reuseaddr tcp:152.32.191.48:4431 & socat UDP-LISTEN:4431,fork,reuseaddr dup:152.32.191.48:4431 & proxy
  47. iftop -n -N -f "host 112.64.175.162" filter the specified network traffic
  48. grep -e "search_word" -rn folder show the line number of fined file
  49. echo $SHELL or ps -p $$ to determine current shell.
  50. ls -l node_modules/* | egrep "^l" output the softlink
  51. find / -name art 2>/dev/null to skip the error output.
  52. curl ip.sb ,curl ident.me , curl ip.cn
  53. %s/phrase to delete//gc delete word in vim.
  54. apt-cache search keyword. ubuntu
  55. npm list --depth=0 2> >(grep -v "extraneous") npm list -s ignore error message.
  56. find ./ -type d -name "node_modules" -exec rm -r {} \; .
  57. docker build . -t application_name -f path_to_dockerfile
  58. git ls-files | grep '\.py' | xargs wc -l list number of code line. find . -name '*.php' | xargs wc -l ,wc -l **/*.tsx.
  59. npm view webpack versions --json
  60. ls -l -sh , du -h for file human readable sizes
  61. ALL_PROXY=socks5://host:port brew update brew upgrade --cask chromedriver
  62. grep " install " /var/log/dpkg.log* installed packages with installation date
  63. sshd -T | grep -E 'gatewayports|allowtcpforwarding' Trouble enabling GatewayPorts for Remote Port Forwarding over SSH
  64. Debug iptables
  65. uptime , last reboot,log show --predicate 'eventMessage contains "reboot"' --last 1h troubleshoot mac reboot issue.
iptables -t raw -A PREROUTING -p tcp --destination 192.168.0.0/24 --dport 80 -j TRACE
iptables -t raw -A OUTPUT -p tcp --destination 192.168.0.0/24 --dport 80 -j TRACE

cat /var/log/kern.log | grep 'TRACE:'  
  1. crontab -l , crontab -e
  2. cat /proc/meminfo, free -g to check memory info
  3. sudo chown --reference ${DEST_DIR} -R ${DEST_DIR}/copied_dir ,chmod --reference=file1 file2
  4. ssh -L local_port:remote_host:remote_port ssh_host make remote resource accessible in client. ssh -D local_port username@server.com as socks5 proxy provider.
  5. list files size du -sh * | sort -h|tail -n 20
  6. copy exclude cp -r ls -A |grep -E -v "@storybook|@nx|typescript|.cache|.bin|@nrwl|@babel|@jest" desition_folder
  7. do the same above rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude --exclude anotherfoldertoexclude

git:
1. git show head~1:/path/to/file
2. git rev-list --all --remotes --pretty=oneline -- src/views/trade/other.vue get the file commit log in all history.
3. git config --system -l to check system check. Then git config --system --unset credential.helper to forget the credential . git config --global credential.helper store enable credentials storage git config --global core.ignorecase true.
4. git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --format="%ai {}" {} | sort retrieve the last date of all files.
5. git diff origin/master > patch,git apply --check xxx.patch,git apply --status xxx.patch, git apply --revers patch to update branch.
6. git reset --hard HEAD^ or git reset --soft HEAD^ to undo a local commit .git revert HEAD then git push origin for remote update.
7. git config credential.helper cache for temporary cache your account infor git config --system --unset credential.helper. 8. git diff ..origin/dev|git apply apply the diff between remote dev to local current head in stage
9. git log --all --decorate --simplify-by-decoration --graph --all --date=relative try to figure the relationship between branch
10. git branch --contains --all $branchName show all branch(include remote) which contain current branch
11. git config --global core.fileMode false ignore.
12. git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit".
13. git log origin/release..HEAD --graph --decorate --oneline show the different commit between branch.
14. gitk --all file will show the all history of the file git checkout -p give you a change to checkout each hun individually
15. unable to access 'https://github.com/xxxx/xxx.git': Failed to connect to 127.0.0.1 port 8087: Connection refused may related to system http proxy env|grep -i proxy.
16. git show-ref --abbrev=7 --tags show tag commit id.
17. cat .git/refs/tags/* show git tag.
18. npm outdated -g npm ls --depth=1 npm la npm show package version npm search npm completion >> ~/.bashrc
19. use git patch cherry pick only one file git diff <branch>..<other-branch> --<fileName> |git apply
20. git show branch:file git merge branch --no-commit --no-ff to ignore no-diff merge .
21. git ignore case default.
22. git apply --3way patchFile.patch Typical fail case applies as much of the patch as it can, and leaves you with conflicts to work out in git however you normally do so.
23. git push --follow-tags only push tag created by git tag -a <tagname> -m '<message>',git push origin tagname push the specified tag.
24. git diff --name-only release-1.1.19..release-1.1.31 -- '*.tsx' -- '*.ts' -- '*.less' show the different between two commit.
25. git fetch --prune --prune-tags origin synchron remote tag with local
26. git push origin branchA:branchB push the nickname.
27. git checkout master and git merge <commit hash> .
28. git log head..origin/master --name-only --no-merges .
29. git merge --no-comit --no-ff branch & git merge --abort to test the merge status.
30. git stash push --keep-index -u stash un-staged,untracked. git stash save --patch.
31. fast-forward.
32. git reset move back the history, git revert add a commit.
33. git add --interactive.
34. git log -u -L <upperLimit>,<lowerLimit>:<path_to_filename> specific the line number 35. git log --all --diff-filter=D --sumary. show the deleted file. git checkout <SHA>^ -- /path/to/file. restore te file
36. git branch --sort=-committerdate descend, git brand --sort=committerdate asecend. git branch -vv.
37. git rebase -i --ignore-date update the date to current time.
38. git config --global core.editor "vim"
39. git log --pretty=format:"%h%x09%an%x09%ad%x09%s" --graph --all --decorate --date=relative --abbrev-commit %h:hash, %x09:tab,%an:author_name,%ad:author_date,%s:subject
40. git merge --no-commit --no-ff $BRANCH test before merge than git merge --continue

VSC:
1. ctrl+D add current selection to match . Ctrl+Shift+D + add all selection .
2. ctrl+shirft+O show symbols (quick variable,method quick goto). 3. ctrl+option+P show next problem.

VIM:
1. ma set mark a, 'a,`a jump to mark a. :marks show the mark list.
2. ctr+z to put vim background, bring it back by fg

mis:

  1. http authcontains basic auth,digest auth.return 401 when auth fail.
  2. simple http get request GET / HTTP/1.1/r/nHost: www.baidu.com/r/n/r/n ,blog
  3. tcp allows for retransimmsion of lst packets gitbook
  4. get script error when cors fundebug
  5. image error do not trigger window.onerror, you have to listen for them specifically mdn
  6. Triggering built-in events
  7. Synchronous JavaScript pauses parsing of the DOM delay the fired of DOMContentLoaded mdn
  8. this is different when use in onClick and addEventListener('click') mdn
  9. use db.things.find( { ln : { $exists : true } } ); to select by the given key nedb
  10. use https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET to get weixin api access_token blog
  11. 30-seconds-of-code了解下git
  12. Greedy/.+/ match as many as possible and lazy/.+?/ as few as possible tutorial
  13. encodeURIComponent will encode =,so encode value not key=value when encode path
  14. server return 304 when request If-Modified-Since<= response Last-Modified and request If-None-Match == response ETag
  15. Promise.reject(1).then(console.log).catch(console.error).then(3=>console.info(3))
  16. X-Forwarded-For, IP Transparency with nginx
  17. [os x locale is not set UTF-8] locale export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 or add ~/.bash_profile then source ~/.bash_profile
  18. w !sudo tee % :w #write a file !sudo #call shell sudo command tee # the output of vi/vim % #trigger the use of current fielname
  19. set up a clean utf8 linux
  20. override pushState and listener for onPopState can watch the url history change. url
  21. echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all for temp allow or append net.ipv4.icmp_echo_ignore_all=1 to /etc/sysctl.conf for save to disk
  22. Data URLS, URLs prefixed with the data: scheme,allow content creators to embed small files inline in documents. mdn
  23. require,the path is relative to that source file(NOT root directory),fs,the pat is relative to process.cwd()(NOT that source file) .You should use path.resolve(__dirname,'../other/module.js')
  24. If the request method is GET or HEAD, XMLHttpRequest will ignore request body .
  25. require vs import link
  26. 204 No Content is meant to say there is no body to return
  27. cache:http://www.baidu.com to see the website cached by google in chrome
  28. babel-plugin-component to require on demand for optimizing code size.
  29. Accept-Language: fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5 // Multiple types, weighted with the quality value syntax:
  30. The old-style backquotes ` ` do treat backslashes and nesting a bit different. The new-style $() interprets everything in between ( ) as a command.
  31. python -m SimpleHTTPServer <port_number> python3 -m http.server
  32. rsync -av --delete source_folder destination_folder
  33. git fetch --prune --prune-tags ,git log --oneline --name-status --grep='Searched phrase'
  34. git log commit-id-before commit-id --stat show the lines added/changed/deleted. (git diff --numstat HEAD~ ).
  35. SELECT db_name() get current database name.
  36. curl -k -O -L https://npmjs.org/install.sh sh install.sh install nodejs.
  37. ^x.y.z stands for version between x.y.z and next major . ~x.y.z means between x.y.z and next minor.
  38. kill $(lsof -ti:3000,3001) kill ports in mac.
  39. time nmap -p 22 portquiz.net test specified port. time nmap portquiz.net popular port. time nmap -p- portquiz.net | grep -i open all outgoing port.(Very slow).
  40. rectangle, alttab, Xnip, keyCastr tool in mac.
  41. mute the soud of tab in window terminal
  42. remote send c when double click.
  43. (fix dock always cover the bottom of application)[https://appuals.com/how-to-fix-mac-dock-getting-stuck/] just killall Dock.
  44. open -e ~/.bashrc mac.
  45. npx kill-port 8080 kill port
  46. Array.from(Array(2), () => new Array(4)) create multi dimension array
  47. pm2 startup to setup auto restart strategy.
  48. 'ThisIsASlug'.replace(/(\w)(?=[/A-Z])/g,'$1 ') split camelCase.
  49. sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder clean mac DNS cache.
  50. -scheme:chrome-extension -scheme:data or scheme:https to filter out extension request in chronium based browser
  51. -scheme:chrome-extension -scheme:data or scheme:https to filter noise request in chrome network tab
  52. git commit --fixup=HEAD and GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash HEAD~2 after git add to quick fixup the commit.

kube:

  1. kubectl logs -l app=elasticsearch -n namespace get all pods log from namspace
  2. docker kill $(docker ps -q) stop all docker containers.
  3. docker exec -ti container_name /bin/bash or docker exec -ti container_name sh
  4. docker container ls|grep "yarn start"|awk '{print $1}'|xargs docker container stop
  5. kubectl get pods -n $namespace show all running pod under namespace.
  6. kubectl exec --stdin --tty $podname -n $namespace -- /bin/bash run the shell environment.
  7. helm search repo $name,helm list -n $namespace
  8. docker container ls -a |grep docker-entry|awk '{print $1}'|xargs docker container rm
  9. docker rmi $(docker images --filter "dangling=true" -q --no-trunc
  10. kubectl describe ingress $container,kubectl describe configmap $container
  11. kubectl exec --stdin --tty $pod -n $namespace -- /bin/sh
  12. kubectl logs pod
  13. kubectl config get-contexts,kubectl config use-context $context , kubectl config set-context --current --namespace=$namespace
  14. kubectl port-forward pod 80:127.0.0.1:8888

About

日常tips


Languages

Language:Shell 100.0%