西维蜀黍

【Linux】Vim

模式切换

  • i → Insert 模式,按 ESC 回到 Normal 模式
  ...


【Linux】Shell - Bash 常用快捷键、命令和工具包

常用快捷键

编辑命令

  • 使用 Ctrl-R 而不是上下光标键来查找历史命令。

  • 使用 Ctrl-W 来删除最后一个单词

  • 使用 Ctrl-U 来删除一行

  • Ctrl + a :移到命令行首

  • Ctrl + e :移到命令行尾

  • Command + K:清空当前 session

  • Alt + f :按单词前移(右向) - 并不行(macOS下用Esc + F)

  • Alt + b :按单词后移(左向) - 并不行(macOS下用Esc + B)

  • Ctrl + u :从光标处删除至命令行首 - macOS下OK

  • Ctrl + k :从光标处删除至命令行尾 - macOS下OK

  • Ctrl + w :从光标处删除至字首 - macOS下OK

  • Alt + d :从光标处删除至字尾

  ...


【Linux】命令 - find

find 命令

Linux find 命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则 find 命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。

$ find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
$ find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
  ...


【Linux】SSH 配置文件(.ssh/config)

Records

  • user’s configuration file (~/.ssh/config)
  • sstem-wide configuration file (/etc/ssh/ssh_config)

参数含义

  • %L 本地主机名的第一个组件
  • %l 本地主机名(包括域名)
  • %h 远程主机名(命令行输入)
  • %n 远程原始主机名
  • %p 远程主机端口
  • %r 远程登录用户名
  • %u 本地 ssh 正在使用的用户名
  • %i 本地 ssh 正在使用 uid
  • %C 值为 %l%h%p%r 的 hash

通配符

  • * - Matches zero or more characters. For example, Host * matches all hosts, while 192.168.0.* matches hosts in the 192.168.0.0/24 subnet.
  • ? - Matches exactly one character. The pattern, Host 10.10.0.? matches all hosts in 10.10.0.[0-9] range.
  • ! - When used at the start of a pattern, it negates the match. For example, Host 10.10.0.* !10.10.0.5 matches any host in the 10.10.0.0/24 subnet except 10.10.0.5.
  ...


【Linux】命令 - ssh

通过 SSH 执行命令

查看远程主机是否运行进程httpd:

$ ssh user@host 'ps ax | grep [h]ttpd'

Demo

-p - 指定连接端口

Port to connect to on the remote host. This can be specified on a per-host basis in the configuration file.

Example

SSH默认端口是22。大多现代的Linux系统22端口是开放的。如果你运行ssh程序而没有指定端口号,它直接就是通过22端口发送请求。

一些系统管理员会改变SSH的默认端口号。让我们试试,现在端口号是1234。要连上主机,就要使用**-p**选项,后面再加上SSH端口

$ ssh 192.168.1.1 -p 1234

要改变端口号,我们需要修改/etc/ssh/ssh_config文件,找到此行:

Port 22

把它换成其他端口号,比如上面的1234.然后重启SSH服务。

  ...


【Network】Speedtest CLI 测速

macOS

brew tap teamookla/speedtest
brew update
brew install speedtest --force

Ubuntu

sudo apt-get install gnupg1 apt-transport-https dirmngr
export INSTALL_KEY=379CE192D401AB61
# Ubuntu versions supported: xenial, bionic
# Debian versions supported: jessie, stretch, buster
export DEB_DISTRO=$(lsb_release -sc)
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $INSTALL_KEY
echo "deb https://ookla.bintray.com/debian ${DEB_DISTRO} main" | sudo tee  /etc/apt/sources.list.d/speedtest.list
sudo apt-get update
# Other non-official binaries will conflict with Speedtest CLI
# Example how to remove using apt-get
# sudo apt-get remove speedtest-cli
sudo apt-get install speedtest
  ...


【MySQL】EXPLAIN 使用

EXPLAIN

The EXPLAIN statement provides information about how MySQL executes statements. EXPLAIN works with SELECT, DELETE, INSERT, REPLACE, and UPDATE statements.

EXPLAIN returns a row of information for each table used in the SELECT statement. It lists the tables in the output in the order that MySQL would read them while processing the statement. MySQL resolves all joins using a nested-loop join method. This means that MySQL reads a row from the first table, and then finds a matching row in the second table, the third table, and so on. When all tables are processed, MySQL outputs the selected columns and backtracks through the table list until a table is found for which there are more matching rows. The next row is read from this table and the process continues with the next table.

  ...


【MySQL】查询结果顺序问题

Answer

In the SQL world, order is not an inherent property of a set of data. Thus, you get no guarantees from your RDBMS that your data will come back in a certain order – or even in a consistent order – unless you query your data with an ORDER BY clause.

  ...


【Linux】配置本地DNS

Linux

Under Linux / UNIX / BSD operating system, you need to edit the /etc/resolv.conf file and add the line:

nameserver {IP-OF-THE-DNS-1}
nameserver {IP-OF-THEISP-DNS-SERVER-2}

Login as the root, enter:

# vi /etc/resolv.conf

OR

$ sudo vi /etc/resolv.conf

Modify or enter nameserver as follows:

nameserver 208.67.222.222
nameserver 208.67.220.220
  ...


【Golang】性能调优 - trace

Tracing

trace 工具可以看到GC被执行的次数和每次执行的时长

Tracing is a way to instrument code to analyze latency throughout the lifecycle of a chain of calls. Go provides golang.org/x/net/trace package as a minimal tracing backend per Go node and provides a minimal instrumentation library with a simple dashboard. Go also provides an execution tracer to trace the runtime events within an interval.

Tracing enables us to:

  • Instrument and analyze application latency in a Go process.
  • Measure the cost of specific calls in a long chain of calls.
  • Figure out the utilization and performance improvements. Bottlenecks are not always obvious without tracing data.
  ...