<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>sre</title>
        <link>https://paragraph.com/@sre</link>
        <description>undefined</description>
        <lastBuildDate>Sat, 16 May 2026 07:14:58 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[数据分析师常用命令]]></title>
            <link>https://paragraph.com/@sre/rAE5z0gFMKi59hHjy4lI</link>
            <guid>rAE5z0gFMKi59hHjy4lI</guid>
            <pubDate>Mon, 07 Mar 2022 15:43:44 GMT</pubDate>
            <description><![CDATA[仅针对mac用户1.ssh篇1.1.怎么弄linux机器的ssh免密码登陆每次都输入用户名密码好烦啊，怎么才能快速登陆linux机器，而不用一遍又一遍的敲又臭又长命令和密码？ 层次一：使用ssh-copy-id快速搞# 假设用户 troy, 机器 10.2.2.2 ssh-copy-id troy@10.2.2.2 相当于将 id_rsa.pub 塞到目标机器目标用户下的 ~/.ssh/authorized_keys 中，这不不用到目标机器上操作，多省事。 如果你从来没有生成功密钥对，那么可以通过以下命令生成：ssh-keygen -t rsa -q -f "$HOME/.ssh/id_rsa" -N "" ls -l $HOME/.ssh/id_rsa* -rw------- 1 troy troy 2602 Dec 21 14:13 /root/.ssh/id_rsa -rw-r--r-- 1 troy troy 566 Dec 21 14:13 /root/.ssh/id_rsa.pub 其中id_rsa为私钥，是你的钥匙，切记保存好，不要给别人id_rsa.pub为公钥，...]]></description>
            <content:encoded><![CDATA[<blockquote><p>仅针对mac用户</p></blockquote><h2 id="h-1ssh" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">1.ssh篇</h2><h3 id="h-11linuxssh" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">1.1.怎么弄linux机器的ssh免密码登陆</h3><p>每次都输入用户名密码好烦啊，怎么才能快速登陆linux机器，而不用一遍又一遍的敲又臭又长命令和密码？</p><p>层次一：使用<code>ssh-copy-id</code>快速搞</p><pre data-type="codeBlock" text="# 假设用户 troy, 机器 10.2.2.2
ssh-copy-id troy@10.2.2.2
"><code><span class="hljs-comment"># 假设用户 troy, 机器 10.2.2.2</span>
ssh-copy-id troy<span class="hljs-meta">@10</span>.<span class="hljs-number">2.2</span>.<span class="hljs-number">2</span>
</code></pre><p>相当于将 <code>id_rsa.pub</code> 塞到目标机器目标用户下的 <code>~/.ssh/authorized_keys</code> 中，这不不用到目标机器上操作，多省事。</p><p><strong>如果你从来没有生成功密钥对，那么可以通过以下命令生成：</strong></p><pre data-type="codeBlock" text="ssh-keygen -t rsa -q -f &quot;$HOME/.ssh/id_rsa&quot; -N &quot;&quot;

ls -l $HOME/.ssh/id_rsa*
-rw------- 1 troy troy 2602 Dec 21 14:13 /root/.ssh/id_rsa
-rw-r--r-- 1 troy troy  566 Dec 21 14:13 /root/.ssh/id_rsa.pub
"><code>ssh<span class="hljs-operator">-</span>keygen <span class="hljs-operator">-</span>t rsa <span class="hljs-operator">-</span>q <span class="hljs-operator">-</span>f <span class="hljs-string">"$HOME/.ssh/id_rsa"</span> <span class="hljs-operator">-</span>N <span class="hljs-string">""</span>

ls <span class="hljs-operator">-</span>l $HOME<span class="hljs-operator">/</span>.ssh/id_rsa<span class="hljs-operator">*</span>
<span class="hljs-operator">-</span>rw<span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span> <span class="hljs-number">1</span> troy troy <span class="hljs-number">2602</span> Dec <span class="hljs-number">21</span> <span class="hljs-number">14</span>:<span class="hljs-number">13</span> <span class="hljs-operator">/</span>root<span class="hljs-operator">/</span>.ssh/id_rsa
<span class="hljs-operator">-</span>rw<span class="hljs-operator">-</span>r<span class="hljs-operator">-</span><span class="hljs-operator">-</span>r<span class="hljs-operator">-</span><span class="hljs-operator">-</span> <span class="hljs-number">1</span> troy troy  <span class="hljs-number">566</span> Dec <span class="hljs-number">21</span> <span class="hljs-number">14</span>:<span class="hljs-number">13</span> <span class="hljs-operator">/</span>root<span class="hljs-operator">/</span>.ssh/id_rsa.pub
</code></pre><ul><li><p>其中<code>id_rsa</code>为私钥，是你的钥匙，切记保存好，不要给别人</p></li><li><p><code>id_rsa.pub</code>为公钥，很好记，它带<code>.pub</code>后缀，就是public的意思，涉及到的场景，基本都是将公钥塞进去，比如git，登陆机器</p></li></ul><p>鉴权做完了，就可以直接登陆了：</p><pre data-type="codeBlock" text="ssh troy@10.2.2.2
"><code>ssh troy<span class="hljs-keyword">@10</span>.2.2.2
</code></pre><p>层次二：使用ssh config管理会话信息</p><p>将一些信息配置到 config 中，作为默认参数，这样就可以直接少输入不少信息</p><pre data-type="codeBlock" text="cat ~/.ssh/config
Host myhost
    HostName 10.2.2.2
    User troy
"><code>cat <span class="hljs-operator">~</span><span class="hljs-operator">/</span>.ssh/config
Host myhost
    HostName <span class="hljs-number">10.2</span><span class="hljs-number">.2</span><span class="hljs-number">.2</span>
    User troy
</code></pre><pre data-type="codeBlock" text="ssh myhost
"><code></code></pre><p>层次三：使用alias，替代固定操作</p><p>分析师可能用到的就那么一台或者多台机器，那么就可以做别名</p><p>在 <code>/etc/profile</code> 添加：</p><pre data-type="codeBlock" text="alias myhost=&quot;ssh troy@10.2.2.2&quot;
"><code>alias <span class="hljs-attr">myhost</span>=<span class="hljs-string">"ssh troy@10.2.2.2"</span>
</code></pre><p>然后 source 使其生效</p><pre data-type="codeBlock" text="source /etc/profile
"><code><span class="hljs-built_in">source</span> /etc/profile
</code></pre><p>**为啥不在bashrc中添加？**因为你可能比较高逼格，也许使用了zsh呢？那读的就是zshrc了，不管你用什么shell，profile一定会读的！！！</p><p>层次四：使用sshw管理多台机器</p><p>有时候管理数十台机器，别名的方式就不太优雅了，那就需要引入工具，要么ui管理，要么命令行管理，这里推荐命令行管理工具。</p><p>详情请参考开源项目：<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/yinheli/sshw">sshw</a></p><p>使用以下命令直接安装：</p><pre data-type="codeBlock" text="cd /tmp &amp;&amp; \
  wget https://github.com/yinheli/sshw/releases/download/v1.1.0/sshw-darwin-amd64-v1.1.0.tar.gz &amp;&amp; \
  tar xf sshw-darwin-amd64-v1.1.0.tar.gz &amp;&amp; \
  mv sshw-darwin-amd64-v1.1.0/sshw /usr/local/bin &amp;&amp; \
  rm -rf /tmp/sshw-darwin-amd64-v1.1.0* &amp;&amp; \
  sshw -h
"><code>cd <span class="hljs-operator">/</span>tmp <span class="hljs-operator">&#x26;</span><span class="hljs-operator">&#x26;</span> \
  wget https:<span class="hljs-comment">//github.com/yinheli/sshw/releases/download/v1.1.0/sshw-darwin-amd64-v1.1.0.tar.gz &#x26;&#x26; \</span>
  tar xf sshw<span class="hljs-operator">-</span>darwin<span class="hljs-operator">-</span>amd64<span class="hljs-operator">-</span>v1<span class="hljs-number">.1</span><span class="hljs-number">.0</span>.tar.gz <span class="hljs-operator">&#x26;</span><span class="hljs-operator">&#x26;</span> \
  mv sshw<span class="hljs-operator">-</span>darwin<span class="hljs-operator">-</span>amd64<span class="hljs-operator">-</span>v1<span class="hljs-number">.1</span><span class="hljs-number">.0</span><span class="hljs-operator">/</span>sshw <span class="hljs-operator">/</span>usr<span class="hljs-operator">/</span>local<span class="hljs-operator">/</span>bin <span class="hljs-operator">&#x26;</span><span class="hljs-operator">&#x26;</span> \
  rm <span class="hljs-operator">-</span>rf <span class="hljs-operator">/</span>tmp<span class="hljs-operator">/</span>sshw<span class="hljs-operator">-</span>darwin<span class="hljs-operator">-</span>amd64<span class="hljs-operator">-</span>v1<span class="hljs-number">.1</span><span class="hljs-number">.0</span><span class="hljs-operator">*</span> <span class="hljs-operator">&#x26;</span><span class="hljs-operator">&#x26;</span> \
  sshw <span class="hljs-operator">-</span>h
</code></pre><p>支持两种模式，一种是自有格式配置文件，另一种是支持ssh config格式，都比较简单。</p><p>上面配置过ssh config，所以这里可以直接使用：</p><pre data-type="codeBlock" text="sshw -s
"><code>sshw <span class="hljs-operator">-</span>s
</code></pre><p>自有格式：</p><pre data-type="codeBlock" text="cat ~/.sshw
- name: myhost
  user: troy
  host: 10.2.2.2
  port: 22
  keypath: /Users/troy/.ssh/id_rsa
"><code>cat <span class="hljs-operator">~</span><span class="hljs-operator">/</span>.sshw
<span class="hljs-operator">-</span> name: myhost
  user: troy
  host: <span class="hljs-number">10.2</span><span class="hljs-number">.2</span><span class="hljs-number">.2</span>
  port: <span class="hljs-number">22</span>
  keypath: <span class="hljs-operator">/</span>Users<span class="hljs-operator">/</span>troy<span class="hljs-operator">/</span>.ssh/id_rsa
</code></pre><p>支持分组，别名，操作方式基本是标准的vim模式，很是方便【当然，前提你得习惯vim键位】具体配置文件配置方式见<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/yinheli/sshw">官方文档</a></p><h2 id="h-2vim" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">2.vim篇</h2><p>linux编辑文件，基本两派：vim派 和 emacs派，大部分是前者。</p><p>vim比较强大方便，这里只说基本的操作，比如模式介绍，怎么退出，怎么保存，怎么复制等...</p><p>算了，还是跟着教程走吧，这个互动教程比我讲得牛逼，贴地址：</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.openvim.com/">openvim.com</a></p><h3 id="h-21" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">2.1.啰嗦两句，整理一下</h3><ol><li><p>多种模式：编辑 、正常 和 可视化</p></li><li><p>怎么进入编辑模式，比如 i啊 a啊</p></li><li><p>怎么进入正常模式，esc</p></li><li><p>常用位移操作 a. 上下左右：hjkl b. 按单词 w b e c. 行首尾 0 ^ $ d. 文档首尾 gg G 2G/2gg e. 数字带位移，比如 5w 10l 2b</p></li><li><p>重复插入 比如插入go三遍 3igo <code>esc</code></p></li><li><p>查找，正着找f，反着找F，比如查找o fo，查找第三个q 3fq</p></li><li><p>比配括号对 %</p></li><li><p>找单词 正找 *；反找 #</p></li><li><p>搜索 /text；用 n 和 N 来跳</p></li><li><p>新行插入 下一行 o；上一行 O</p></li><li><p>删除 x d dw dG dgg d2w d2e</p></li><li><p>替换 r</p></li><li><p>神奇操作，重复上一个操作 .</p></li><li><p>v进入可视化模式，通过位移加指令操作</p></li><li><p>保存 :w 退出 :q 保存退出 :wq 简化版 :x 强制带!</p></li></ol><h3 id="h-22" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">2.2.教程中的</h3><pre data-type="codeBlock" text="i, I
change to insert mode

h, j, k, l
move left, down, up, right

w, b, e, ge
move word at a time

[n][action/movement]
do n times, e.g. 3w

x, X
remove a character

a, A
append

f[char]
move to next given char in line

F[char]
move to previous char in line

; and ,
repeat last f or F

/yourtext and then: n, N
Search text

d[movement]
delete by giving movement

r[char]
replaces character below cursor

0, $
move to start/end of line

o, O
add new line

%
Goto corresponding parentheses

ci[movement]
change inside of given movement

D
delete to end of line

S
clear current line; to insert mode

gg / G
move to start / end of buffer

yy
copy current line

p
Paste copied text after cursor.
"><code>i, I
change to insert mode

h, j, k, l
move left, down, up, right

w, b, e, ge
move <span class="hljs-type">word</span> at a time

[n][action/movement]
<span class="hljs-keyword">do</span> n times, e.g. <span class="hljs-number">3</span>w

x, X
remove a character

a, A
append

f[<span class="hljs-type">char</span>]
move to next given <span class="hljs-type">char</span> in line

F[<span class="hljs-type">char</span>]
move to previous <span class="hljs-type">char</span> in line

; <span class="hljs-keyword">and</span> ,
repeat last f <span class="hljs-keyword">or</span> F

/yourtext <span class="hljs-keyword">and</span> then: n, N
Search text

d[movement]
<span class="hljs-keyword">delete</span> by giving movement

r[<span class="hljs-type">char</span>]
replaces character below cursor

<span class="hljs-number">0</span>, $
move to start/end of line

o, O
add <span class="hljs-keyword">new</span> line

%
Goto corresponding parentheses

ci[movement]
change inside of given movement

D
<span class="hljs-keyword">delete</span> to end of line

S
clear current line; to insert mode

gg / G
move to start / end of buffer

yy
copy current line

p
Paste copied text after cursor.
</code></pre><p><strong>总结</strong></p><ul><li><p>vim的操作命令很好记，可以按单词首字母进行记忆，多操作可合理组合，比如 <code>数字位移操作</code> 的组合</p></li><li><p>入门其实了解模式，知道怎么进入编辑模式，怎么退出编辑模式进入正常模式，知道怎么保存退出就行了，毕竟大部分的键盘还有方向键，对不？？</p></li><li><p>入门一句话：vim a.txt -&gt; i -&gt; 方向键挪 -&gt; 编辑 -&gt; esc -&gt; wq/q!</p></li><li><p>操作类的没有捷径可走，掌握道，然后勤加操练即可</p></li><li><p>感兴趣了，可以深入vim配置；使用vim做日常工作/开发（插件一装，花里胡哨，实乃装逼利器！！！）</p></li></ul>]]></content:encoded>
            <author>sre@newsletter.paragraph.com (sre)</author>
        </item>
    </channel>
</rss>