<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>Technology｜林鼎淵 Dean Lin</title>
    <link>https://deanlin.net/tags/technology/</link>
    <image><url>https://deanlin.net/images/author_hu_aa256fc934e9a932.jpg</url><title>Technology｜林鼎淵 Dean Lin</title><link>https://deanlin.net/tags/technology/</link><width>144</width><height>144</height></image>
    <description>林鼎淵（Dean Lin）的部落格：生成式 AI 企業內訓講師、外商資安公司軟體專家、7 本書作者。400 多篇文章用白話分享生成式 AI 實戰、Claude Code 與 Vibe Coding 教學、團隊合作與職場成長。</description>
    <generator>Hugo</generator>
    <language>zh-tw</language>
    <copyright>© 2020–2026 林鼎淵 Dean Lin</copyright>
    <lastBuildDate>Fri, 21 Apr 2023 18:20:06 +0800</lastBuildDate>
    <atom:link href="https://deanlin.net/tags/technology/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>只要 5 步驟！用 Midjourney 幫 Model 換衣服</title>
      <link>https://deanlin.net/blog/202304/midjourney-change-outfits/</link>
      <pubDate>Fri, 21 Apr 2023 18:20:06 +0800</pubDate>
      <guid>https://deanlin.net/blog/202304/midjourney-change-outfits/</guid>
      <dc:creator>林鼎淵</dc:creator>
      <category>AI 實戰</category>
      <description>難道外拍 Model 也受到 AI 衝擊要失業了嗎？今天這篇文章將會跟讀者分享如何用 Midjourney 幫 Model 換上指定服飾，並說明不同款式衣服會面臨的問題。</description>
      <media:content url="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-og_hu_e2366c702afa510d.jpg" medium="image" type="image/jpeg" width="1200" height="675" />
      <content:encoded><![CDATA[<p>難道外拍 Model 也受到 AI 衝擊要失業了嗎？今天這篇文章將會跟讀者分享如何用 Midjourney 幫 Model 換上指定服飾，並說明不同款式衣服會面臨的問題。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-01.webp" width="1144" height="619" alt="只要 5 步驟！用 Midjourney 幫 Model 換衣服（圖 1）" fetchpriority="high" decoding="async"></p>
<pre tabindex="0"><code>大綱

STEP 1：產生 Model 照片
STEP 2：產生衣服素材
STEP 3：透過任何工具將兩張圖片疊在一起（不用很精準）
STEP 4：將圖貼到 Ｍidjourney，並複製連結
STEP 5：幫 Model 換衣服
</code></pre><h2 id="step-1產生-model-照片">STEP 1：產生 Model 照片<a class="h-anchor" href="#step-1%e7%94%a2%e7%94%9f-model-%e7%85%a7%e7%89%87" aria-label="這個段落的連結"></a></h2>
<p>Prompt：「 <code>Full Body photograph of a Chinese female model standing in front of bright wall. High detail, 8k, bright &ndash;ar 9:16 &ndash;v 5</code>」</p>
<blockquote>
<p>中國 Model 的全身照片，站在亮麗的牆前面，高度細節、8k 畫質、圖片比例 9:16、Version 5</p>
</blockquote>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-02.webp" width="536" height="956" alt="STEP 1：產生 Model 照片（圖 2）" loading="lazy" decoding="async"></p>
<p>這邊我選擇「右上」的圖。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-03.webp" width="536" height="956" alt="STEP 1：產生 Model 照片（圖 3）" loading="lazy" decoding="async"></p>
<hr>
<h2 id="step-2產生衣服素材">STEP 2：產生衣服素材<a class="h-anchor" href="#step-2%e7%94%a2%e7%94%9f%e8%a1%a3%e6%9c%8d%e7%b4%a0%e6%9d%90" aria-label="這個段落的連結"></a></h2>
<p>Prompt：「<code>plain shirt in white background &ndash;v 5</code>」</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-04.webp" width="956" height="956" alt="STEP 2：產生衣服素材（圖 4）" loading="lazy" decoding="async"></p>
<p>Prompt：「<code>plaid shirt in white background &ndash;v 5</code>」</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-05.webp" width="956" height="956" alt="STEP 2：產生衣服素材（圖 5）" loading="lazy" decoding="async"></p>
<p>Prompt：「<code>cartoon logo shirt in white background &ndash;v 5</code>」</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-06.webp" width="956" height="956" alt="STEP 2：產生衣服素材（圖 6）" loading="lazy" decoding="async"></p>
<hr>
<h2 id="step-3透過任何工具將兩張圖片疊在一起不用很精準">STEP 3：透過任何工具將兩張圖片疊在一起（不用很精準）<a class="h-anchor" href="#step-3%e9%80%8f%e9%81%8e%e4%bb%bb%e4%bd%95%e5%b7%a5%e5%85%b7%e5%b0%87%e5%85%a9%e5%bc%b5%e5%9c%96%e7%89%87%e7%96%8a%e5%9c%a8%e4%b8%80%e8%b5%b7%e4%b8%8d%e7%94%a8%e5%be%88%e7%b2%be%e6%ba%96" aria-label="這個段落的連結"></a></h2>
<p>你可以使用任何去背工具，這邊筆者是用：<a href="https://www.remove.bg/">https://www.remove.bg/</a></p>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-07.webp" width="1400" height="579" alt="STEP 3：透過任何工具將兩張圖片疊在一起（不用很精準）（圖 7）" loading="lazy" decoding="async"></p>
<p>然後將兩張圖疊在一起，筆者用 PPT 無腦操作。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-08.webp" width="1300" height="1154" alt="STEP 3：透過任何工具將兩張圖片疊在一起（不用很精準）（圖 8）" loading="lazy" decoding="async"></p>
<hr>
<h2 id="step-4將圖貼到-midjourney並複製連結">STEP 4：將圖貼到 Midjourney，並複製連結<a class="h-anchor" href="#step-4%e5%b0%87%e5%9c%96%e8%b2%bc%e5%88%b0-midjourney%e4%b8%a6%e8%a4%87%e8%a3%bd%e9%80%a3%e7%b5%90" aria-label="這個段落的連結"></a></h2>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-09.webp" width="993" height="655" alt="STEP 4：將圖貼到 Midjourney，並複製連結（圖 9）" loading="lazy" decoding="async"></p>
<hr>
<h2 id="step-5幫-model-換衣服">STEP 5：幫 Model 換衣服<a class="h-anchor" href="#step-5%e5%b9%ab-model-%e6%8f%9b%e8%a1%a3%e6%9c%8d" aria-label="這個段落的連結"></a></h2>
<p>先貼上連結，並將一開始的 Prompt 原封不動的貼到後面，最後記得要加上「 <code>&ndash;iw 2</code>」，將權重調到最高。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-10.webp" width="1099" height="645" alt="STEP 5：幫 Model 換衣服（圖 10）" loading="lazy" decoding="async"></p>
<p>然後就換成功嚕！</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-11.webp" width="1400" height="2498" alt="STEP 5：幫 Model 換衣服（圖 11）" loading="lazy" decoding="async"></p>
<p>筆者目前實驗下來，素色的衣服最容易被吃進去；像是下面有格子狀的襯衫顏色不太穩定，且版型跟原圖有一定的差異。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-12.webp" width="1400" height="2498" alt="STEP 5：幫 Model 換衣服（圖 12）" loading="lazy" decoding="async"></p>
<p>如果是有圖案的衣服，那效果就更糟糕了，他有很大的機率變成其他圖案。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-13.webp" width="1400" height="2498" alt="STEP 5：幫 Model 換衣服（圖 13）" loading="lazy" decoding="async"></p>
<hr>
<h2 id="總結">總結<a class="h-anchor" href="#%e7%b8%bd%e7%b5%90" aria-label="這個段落的連結"></a></h2>
<ol>
<li>操作非常簡單，會用電腦的人都能操作。</li>
<li>如果衣服款式比較簡單，對人物姿勢沒有太大要求，那成功率上升很多。</li>
<li>如果衣服上有圖案、複雜細節，那產出來的結果幾乎不可控制。</li>
</ol>
<p>如果把 AI 產出來的圖拿來當商用素材（ex：電商平台），那可能會遇到一些細節不一致的問題，是有可能造成買賣糾紛的。</p>
<p>不過如果你把他當成「發想」的工具，那筆者覺得幫助就很大；像是服飾穿搭、顏色搭配、Model 姿勢…等等。</p>
<hr>
<a class="linkcard" href="https://deanlin.net/categories/ai/">
  <span class="lc-body">
    <span class="lc-title">AI 實戰</span>
    <span class="lc-desc">實測生成式 AI 工具、Vibe Coding 與自動化流程的第一手心得，把 AI 變成每天都用得上的即戰力。</span>
    <span class="lc-site"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M5 12h14M13 6l6 6-6 6"/></svg>林鼎淵 Dean Lin</span>
  </span>
</a>

<p><strong>想將 AI 導入自己的職場與生活嗎？歡迎<a href="https://www.books.com.tw/products/0011004216">購買筆者出版的新書</a></strong>，幫助您<strong>在 AI 的浪潮中站穩腳步，並在未來的職場競爭中佔據優勢！</strong></p>
<figure class="figure"><img src="https://deanlin.net/blog/202304/midjourney-change-outfits/images/midjourney-change-outfits-14.webp" width="1400" height="319" alt="林鼎淵著作《ChatGPT 與 AI 繪圖效率大師（新增 Copilot、Gamma、Runway、Suno）》" loading="lazy" decoding="async">
  <figcaption><a href="https://www.books.com.tw/products/0011004216">https://www.books.com.tw/products/0011004216</a></figcaption>
</figure>

]]></content:encoded>
    </item>
    <item>
      <title>【Midjourney 新手常見問題】圖片合成、排除物件、透明背景、以圖生圖</title>
      <link>https://deanlin.net/blog/202304/midjourney-faq/</link>
      <pubDate>Wed, 12 Apr 2023 22:45:37 +0800</pubDate>
      <guid>https://deanlin.net/blog/202304/midjourney-faq/</guid>
      <dc:creator>林鼎淵</dc:creator>
      <category>AI 實戰</category>
      <description>在這篇文章中，筆者收錄了幾個最常被問的 Midjourney 操作問題（圖片合成、排除物件、透明背景、以圖生圖），希望能給剛入門的新手一些幫助與使用指引。</description>
      <media:content url="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-og_hu_4d13abc358971590.jpg" medium="image" type="image/jpeg" width="1200" height="675" />
      <content:encoded><![CDATA[<p>在這篇文章中，筆者收錄了幾個最常被問的 Midjourney 操作問題（圖片合成、排除物件、透明背景、以圖生圖），希望能給剛入門的新手一些幫助與使用指引。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-01.webp" width="1178" height="646" alt="【Midjourney 新手常見問題】圖片合成、排除物件、透明背景、以圖生圖（圖 1）" fetchpriority="high" decoding="async"></p>
<h2 id="圖片合成">圖片合成<a class="h-anchor" href="#%e5%9c%96%e7%89%87%e5%90%88%e6%88%90" aria-label="這個段落的連結"></a></h2>
<p><strong>方法 1</strong>：用「/imagine」將兩個網址用「 , 」區隔即可合成。</p>
<p>這邊我用維基百科上找到的「拿破崙」與「莫扎特」做合成。</p>
<div class="gallery-row cols-2">

<figure class="figure"><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-02.webp" width="800" height="938" alt="圖片合成（圖 2）" loading="lazy" decoding="async">
</figure>

<figure class="figure"><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-03.webp" width="800" height="1025" alt="圖片來源：維基百科" loading="lazy" decoding="async">
  <figcaption>圖片來源：維基百科</figcaption>
</figure>


</div>

<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-04.webp" width="1400" height="278" alt="圖片合成（圖 4）" loading="lazy" decoding="async"></p>
<p>合成後，網址會變轉換成短網址；同時我們可以獲得「莫扎特」與「拿破崙」的合體照（聽起來怪怪的XD）。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-05.webp" width="991" height="747" alt="圖片合成（圖 5）" loading="lazy" decoding="async"></p>
<p><strong>方法 2</strong>：用「/blend」方法，將圖片貼上合成（最多 5 張）。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-06.webp" width="1400" height="509" alt="圖片合成（圖 6）" loading="lazy" decoding="async"></p>
<p>這邊我選用燈泡跟兔子做為材料。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-07.webp" width="1400" height="553" alt="圖片合成（圖 7）" loading="lazy" decoding="async"></p>
<p>最終合成出一個兔子燈的成果。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-08.webp" width="1000" height="749" alt="圖片合成（圖 8）" loading="lazy" decoding="async"></p>
<hr>
<h2 id="排除物件">排除物件<a class="h-anchor" href="#%e6%8e%92%e9%99%a4%e7%89%a9%e4%bb%b6" aria-label="這個段落的連結"></a></h2>
<p>可以透過「 — no xxx」來排除物件。</p>
<ul>
<li><code>&ndash;no people</code>：不要人。</li>
<li><code>&ndash;no chair</code>：不要椅子。</li>
</ul>
<p>這邊我用「Interior of modern coffee cafe（現代咖啡館的內部）」作為 Prompt，會得到擺設含有椅子的咖啡館。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-09.webp" width="680" height="706" alt="排除物件（圖 9）" loading="lazy" decoding="async"></p>
<p>如果我希望擺設不含椅子，我就加上 <code>&ndash;no chair</code> 的參數，Prompt 改成「Interior of modern coffee cafe &ndash;no chair」。</p>
<p>從下圖我們可以看到咖啡廳就沒有椅子了。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-10.webp" width="765" height="747" alt="排除物件（圖 10）" loading="lazy" decoding="async"></p>
<hr>
<h2 id="白色背景去背">白色背景、去背<a class="h-anchor" href="#%e7%99%bd%e8%89%b2%e8%83%8c%e6%99%af%e5%8e%bb%e8%83%8c" aria-label="這個段落的連結"></a></h2>
<p>我們可以用「in white background」來取得乾淨的背景。</p>
<p>這邊我先用「battle of two warriors（兩個戰士的戰鬥）」作為 Prompt，你會獲得不好去背的背景。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-11.webp" width="765" height="747" alt="白色背景、去背（圖 11）" loading="lazy" decoding="async"></p>
<p>調整成「battle of two warriors <code>in white background</code>」作為 Prompt，你會獲得乾淨的背景。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-12.webp" width="781" height="699" alt="白色背景、去背（圖 12）" loading="lazy" decoding="async"></p>
<p>這個時候透過去背服務的工具如：<a href="https://www.remove.bg/">https://www.remove.bg/</a></p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-13.webp" width="1388" height="895" alt="白色背景、去背（圖 13）" loading="lazy" decoding="async"></p>
<p>便可輕鬆去背。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-14.webp" width="1388" height="730" alt="白色背景、去背（圖 14）" loading="lazy" decoding="async"></p>
<hr>
<h2 id="以圖生圖">以圖生圖<a class="h-anchor" href="#%e4%bb%a5%e5%9c%96%e7%94%9f%e5%9c%96" aria-label="這個段落的連結"></a></h2>
<p>我們可以自己提供圖片，然後加上文字敘述改變圖片風格，Prompt 結構：「<code>jpg 或 png 結尾的 url</code> <code>描述</code>」，中間要記得空一格！</p>
<p>下面我就用筆者的照片作為範例，請他幫我用 Miyazaki Hayao（宮崎駿）的風格呈現。</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-15.webp" width="939" height="615" alt="以圖生圖（圖 15）" loading="lazy" decoding="async"></p>
<p>從產出的結果來看，感覺瞬間 +40 歲 XD</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-16.webp" width="939" height="709" alt="以圖生圖（圖 16）" loading="lazy" decoding="async"></p>
<p>下面改成用 botw（曠野之息）的風格，又瞬間 -10 歲惹 XD</p>
<p><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-17.webp" width="929" height="736" alt="以圖生圖（圖 17）" loading="lazy" decoding="async"></p>
<hr>
<a class="linkcard" href="https://deanlin.net/categories/ai/">
  <span class="lc-body">
    <span class="lc-title">AI 實戰</span>
    <span class="lc-desc">實測生成式 AI 工具、Vibe Coding 與自動化流程的第一手心得，把 AI 變成每天都用得上的即戰力。</span>
    <span class="lc-site"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M5 12h14M13 6l6 6-6 6"/></svg>林鼎淵 Dean Lin</span>
  </span>
</a>

<p><strong>想將 AI 導入自己的職場與生活嗎？歡迎<a href="https://www.books.com.tw/products/0011004216">購買筆者出版的新書</a></strong>，幫助您<strong>在 AI 的浪潮中站穩腳步，並在未來的職場競爭中佔據優勢！</strong></p>
<figure class="figure"><img src="https://deanlin.net/blog/202304/midjourney-faq/images/midjourney-faq-18.webp" width="1400" height="319" alt="林鼎淵著作《ChatGPT 與 AI 繪圖效率大師（新增 Copilot、Gamma、Runway、Suno）》" loading="lazy" decoding="async">
  <figcaption><a href="https://www.books.com.tw/products/0011004216">https://www.books.com.tw/products/0011004216</a></figcaption>
</figure>

]]></content:encoded>
    </item>
    <item>
      <title>那些沒人教你又超實用的 Linux 指令</title>
      <link>https://deanlin.net/blog/202208/useful-linux-commands/</link>
      <pubDate>Wed, 17 Aug 2022 17:59:44 +0800</pubDate>
      <guid>https://deanlin.net/blog/202208/useful-linux-commands/</guid>
      <dc:creator>林鼎淵</dc:creator>
      <category>技術教學</category>
      <description>儘管在 Linux 用 cd、vi、mv、cp、rm、ls 這些基礎指令就能滿足大部分的需求，但遇到一些特殊狀況時，這些指令就不夠用了。這篇文章彙整了筆者常用的 Linux 指令，以「vim 編輯器、查詢 Server 各項資源、檢查網路環境」為主。</description>
      <media:content url="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-og_hu_eadb6778986bc128.jpg" medium="image" type="image/jpeg" width="1200" height="675" />
      <content:encoded><![CDATA[<p>儘管在 Linux 用 cd、vi、mv、cp、rm、ls 這些基礎指令就能滿足大部分的需求，但遇到一些特殊狀況時，這些指令就不夠用了。</p>
<p>這篇文章彙整了筆者常用的 Linux 指令，以「vim 編輯器、查詢 Server 各項資源、檢查網路環境」為主。</p>
<p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-01.webp" width="1400" height="730" alt="那些沒人教你又超實用的 Linux 指令（圖 1）" fetchpriority="high" decoding="async"></p>
<pre tabindex="0"><code>大綱
▋ vim 編輯器常用指令
 ➤ 顯示行數（:set number）
 ➤ 前往指定行數（:行數）
 ➤ 刪除多行
 ➤ 大量註解/反註解
 ➤ 搜尋文字並取代
▋ 查詢 Server 各項資源
 ➤ Server 啟動多久了（uptime）
 ➤ 找出最耗費資源的程式（top）
 ➤ 以目錄形式呈現目前磁碟使用狀況（ncdu）
 ➤ 搜尋檔案（find）
 ➤ 搜尋歷史指令（Control+R）
▋ 檢查網路環境
 ➤ 網路診斷瑞士刀（nc）
 ➤ 設定好 DNS 後，確認回應是否正常（nslookup）
 ➤ 查詢佔用的 port（lsof）
</code></pre><h2 id="-vim-編輯器常用指令">vim 編輯器常用指令<a class="h-anchor" href="#-vim-%e7%b7%a8%e8%bc%af%e5%99%a8%e5%b8%b8%e7%94%a8%e6%8c%87%e4%bb%a4" aria-label="這個段落的連結"></a></h2>
<p>有時我們會需要進入 Server 做一些緊急調整（ex：Debug 時），搭配下面的操作可以增進你的效率。</p>
<h3 id="-顯示行數set-number">顯示行數（:set number）<a class="h-anchor" href="#-%e9%a1%af%e7%a4%ba%e8%a1%8c%e6%95%b8set-number" aria-label="這個段落的連結"></a></h3>
<p>方便與 Local 端程式做比對。</p>
<p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-02.webp" width="1400" height="944" alt="顯示行數（:set number）（圖 2）" loading="lazy" decoding="async"></p>
<h3 id="-前往指定行數行數">前往指定行數（:行數）<a class="h-anchor" href="#-%e5%89%8d%e5%be%80%e6%8c%87%e5%ae%9a%e8%a1%8c%e6%95%b8%e8%a1%8c%e6%95%b8" aria-label="這個段落的連結"></a></h3>
<p>直接跳轉到你要修改的位置。</p>
<figure class="figure figure-video">
  <video class="gifv" muted loop playsinline controls preload="none" poster="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-03.webp" width="950" height="658" aria-label="前往指定行數（:行數）（圖 3）" data-gifv>
    <source src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-03.mp4" type="video/mp4">
  </video>
</figure>

<h3 id="-刪除多行">刪除多行<a class="h-anchor" href="#-%e5%88%aa%e9%99%a4%e5%a4%9a%e8%a1%8c" aria-label="這個段落的連結"></a></h3>
<p>刪除一行的指令是「<code>dd</code>」，但如果有幾十行甚至上百行需要刪除，那會 dd 到崩潰，而且很容易有誤刪的情形。</p>
<ul>
<li>刪除從游標開始的 N 行（ex：刪除 5 行就是 <code>5dd</code>）</li>
</ul>
<figure class="figure figure-video">
  <video class="gifv" muted loop playsinline controls preload="none" poster="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-04.webp" width="960" height="651" aria-label="可以觀察右下角，會看到我的輸入" data-gifv>
    <source src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-04.mp4" type="video/mp4">
  </video>
  <figcaption>可以觀察右下角，會看到我的輸入</figcaption>
</figure>

<ul>
<li>刪除指定開始、結束的行 <code>:[start],[end]d</code> （ex：刪除第 3~17 行 <code>3,17d</code>）</li>
</ul>
<figure class="figure figure-video">
  <video class="gifv" muted loop playsinline controls preload="none" poster="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-05.webp" width="960" height="651" aria-label="刪除多行（圖 5）" data-gifv>
    <source src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-05.mp4" type="video/mp4">
  </video>
</figure>

<h3 id="-大量註解反註解">大量註解/反註解<a class="h-anchor" href="#-%e5%a4%a7%e9%87%8f%e8%a8%bb%e8%a7%a3%e5%8f%8d%e8%a8%bb%e8%a7%a3" aria-label="這個段落的連結"></a></h3>
<p>有時我們不是要刪除程式，只是想要把一定範圍內的程式註解起來做一些測試或是 Debug，如果你依靠「<code>i</code>」來慢慢編輯，真的會心死。</p>
<ul>
<li><strong>大量註解</strong>：先將游標移至想開始註解的行，按「Control+v」進入 VISUAL BLOCK 模式，接著選擇想要註解的區塊；按下「Shift+i」進入編輯模式填寫註解符號（ex：<code>//</code>），按「Esc」離開。</li>
</ul>
<figure class="figure figure-video">
  <video class="gifv" muted loop playsinline controls preload="none" poster="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-06.webp" width="960" height="651" aria-label="大量註解/反註解（圖 6）" data-gifv>
    <source src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-06.mp4" type="video/mp4">
  </video>
</figure>

<ul>
<li><strong>反註解</strong>：先將游標移至想開始註解的行，按「Control+v」進入 VISUAL BLOCK 模式，接著選擇想要反註解的區塊（因為我的註解用<code>//</code>所以要按右鍵刪除兩列）；按下「d」刪除註解。</li>
</ul>
<figure class="figure figure-video">
  <video class="gifv" muted loop playsinline controls preload="none" poster="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-07.webp" width="960" height="651" aria-label="大量註解/反註解（圖 7）" data-gifv>
    <source src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-07.mp4" type="video/mp4">
  </video>
</figure>

<h3 id="-搜尋文字並取代">搜尋文字並取代<a class="h-anchor" href="#-%e6%90%9c%e5%b0%8b%e6%96%87%e5%ad%97%e4%b8%a6%e5%8f%96%e4%bb%a3" aria-label="這個段落的連結"></a></h3>
<pre tabindex="0"><code>:[範圍]s/[比對字串]/[取代字串]/g
</code></pre><ul>
<li>將全部的「test」取代為「try」： <code>:%s/test/try/g</code></li>
</ul>
<figure class="figure figure-video">
  <video class="gifv" muted loop playsinline controls preload="none" poster="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-08.webp" width="960" height="651" aria-label="搜尋文字並取代（圖 8）" data-gifv>
    <source src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-08.mp4" type="video/mp4">
  </video>
</figure>

<ul>
<li>將 1~10 行的「test」取代為「try」：<code>:1,10s/test/try/g</code></li>
</ul>
<figure class="figure figure-video">
  <video class="gifv" muted loop playsinline controls preload="none" poster="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-09.webp" width="960" height="651" aria-label="搜尋文字並取代（圖 9）" data-gifv>
    <source src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-09.mp4" type="video/mp4">
  </video>
</figure>

<hr>
<h2 id="-查詢-server-各項資源">查詢 Server 各項資源<a class="h-anchor" href="#-%e6%9f%a5%e8%a9%a2-server-%e5%90%84%e9%a0%85%e8%b3%87%e6%ba%90" aria-label="這個段落的連結"></a></h2>
<p>了解資源的使用狀況，可以幫你更快地找出問題點，與優化方向。</p>
<h3 id="-server-啟動多久了uptime">Server 啟動多久了（uptime）<a class="h-anchor" href="#-server-%e5%95%9f%e5%8b%95%e5%a4%9a%e4%b9%85%e4%ba%86uptime" aria-label="這個段落的連結"></a></h3>
<p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-10.webp" width="1400" height="87" alt="Server 啟動多久了（uptime）（圖 10）" loading="lazy" decoding="async"></p>
<ul>
<li><strong>21:21:33</strong>：系統時間</li>
<li><strong>up 6 days, 7:40</strong>：Server 已執行時間，時間越大代表越穩定。</li>
<li><strong>1 user</strong>：使用者總連線數（注意不是使用者數！）。</li>
<li><strong>load average：</strong>系統平均負載狀況，顯示1 / 5 / 15 分鐘的系統平均負載（以單核 CPU 來說，建議數值不大於 3，超過 5 就需要注意了）。</li>
</ul>
<h3 id="-找出最耗費資源的程式top">找出最耗費資源的程式（top）<a class="h-anchor" href="#-%e6%89%be%e5%87%ba%e6%9c%80%e8%80%97%e8%b2%bb%e8%b3%87%e6%ba%90%e7%9a%84%e7%a8%8b%e5%bc%8ftop" aria-label="這個段落的連結"></a></h3>
<p><code>top</code> 這個指令會顯示 Server 即時的資源使用狀況。</p>
<p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-11.webp" width="1400" height="979" alt="找出最耗費資源的程式（top）（圖 11）" loading="lazy" decoding="async"></p>
<p>top 也可以指定欄位做排序，以下面的指令（ <code>top -b -o +%MEM | head -n 17</code>）為例，他是指：</p>
<ul>
<li><strong>-b</strong>：以 batch 模式輸出報表。</li>
<li><strong>-o</strong>：我們使用「%MEM」這個欄位，以「正序」來排序。</li>
<li><strong>head -n 17</strong>：因為上面的資訊就佔了 7 行，所以你想要顯示前 10 名就要用 10+7=17。</li>
</ul>
<p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-12.webp" width="1400" height="696" alt="找出最耗費資源的程式（top）（圖 12）" loading="lazy" decoding="async"></p>
<blockquote>
<p>在找出最耗費資源的程式後，有時會搭配 <code>kill [PID]</code> 的方式來終止程式；如果無法順利終止，可使用 <code>kill -9 [PID]</code> 來強行終止。</p>
</blockquote>
<h3 id="-以目錄形式呈現目前磁碟使用狀況ncdu">以目錄形式呈現目前磁碟使用狀況（ncdu）<a class="h-anchor" href="#-%e4%bb%a5%e7%9b%ae%e9%8c%84%e5%bd%a2%e5%bc%8f%e5%91%88%e7%8f%be%e7%9b%ae%e5%89%8d%e7%a3%81%e7%a2%9f%e4%bd%bf%e7%94%a8%e7%8b%80%e6%b3%81ncdu" aria-label="這個段落的連結"></a></h3>
<p>如果發現磁碟空間快滿了，又不確定哪個資料夾佔用了大量空間，<code>ncdu</code> 可以幫你高效率的檢查（指令會以你當前的目錄來做顯示，）。</p>
<p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-13.webp" width="1400" height="302" alt="以目錄形式呈現目前磁碟使用狀況（ncdu）（圖 13）" loading="lazy" decoding="async"></p>
<p>如果你想要掃描根目錄硬碟使用狀況，請使用 <code>ncdu -x /</code>，若要退出請按 <code>q</code> 。</p>
<p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-14.webp" width="1400" height="322" alt="以目錄形式呈現目前磁碟使用狀況（ncdu）（圖 14）" loading="lazy" decoding="async"></p>
<blockquote>
<p>此指令並非預設安裝，Ubuntu 環境下的安裝指令為： <code>apt-get -y install ncdu</code></p>
</blockquote>
<h3 id="-搜尋檔案find">搜尋檔案（find）<a class="h-anchor" href="#-%e6%90%9c%e5%b0%8b%e6%aa%94%e6%a1%88find" aria-label="這個段落的連結"></a></h3>
<p>假使我們想從根目錄開始搜尋「php.ini」在哪裡：</p>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo find / -name php.ini
</span></span></code></pre></div><p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-15.webp" width="1400" height="335" alt="搜尋檔案（find）（圖 15）" loading="lazy" decoding="async"></p>
<p>如果我們不確定檔名，也可以透過「?」來進行模糊搜尋：</p>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo find / -name ph?.ini
</span></span></code></pre></div><p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-16.webp" width="1400" height="326" alt="搜尋檔案（find）（圖 16）" loading="lazy" decoding="async"></p>
<h3 id="-搜尋歷史指令controlr">搜尋歷史指令（Control+R）<a class="h-anchor" href="#-%e6%90%9c%e5%b0%8b%e6%ad%b7%e5%8f%b2%e6%8c%87%e4%bb%a4controlr" aria-label="這個段落的連結"></a></h3>
<p>有時我們會用到帶有一長串噁心的參數的指令，這些指令只要下過一次後 history 就會記住。</p>
<p>因此我們下次想要再使用它時，只要按下「Control+R」輸入要搜尋的字串，bash 就會顯示最近一項匹配的指令；連續按「Control+R」則繼續搜尋更早的歷史指令，按「Enter」則會執行顯示的指令。</p>
<figure class="figure figure-video">
  <video class="gifv" muted loop playsinline controls preload="none" poster="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-17.webp" width="960" height="645" aria-label="搜尋歷史指令（Control&#43;R）（圖 17）" data-gifv>
    <source src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-17.mp4" type="video/mp4">
  </video>
</figure>

<hr>
<h2 id="-檢查網路環境">檢查網路環境<a class="h-anchor" href="#-%e6%aa%a2%e6%9f%a5%e7%b6%b2%e8%b7%af%e7%92%b0%e5%a2%83" aria-label="這個段落的連結"></a></h2>
<p>想要知道網路彼此環境的狀況，除了用最基礎的 <code>ping</code> 以外，下面這些指令可以幫你獲得更詳盡的資訊。</p>
<h3 id="-網路診斷瑞士刀nc">網路診斷瑞士刀（nc）<a class="h-anchor" href="#-%e7%b6%b2%e8%b7%af%e8%a8%ba%e6%96%b7%e7%91%9e%e5%a3%ab%e5%88%80nc" aria-label="這個段落的連結"></a></h3>
<p>Netcat （nc）能夠做到的事情很多，這邊跟大家分享常用的功能。</p>
<ul>
<li><strong>測試目標 Server 特定的 port 是否開啟： <code>nc -v [host] [port]</code></strong></li>
</ul>
<p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-18.webp" width="1400" height="256" alt="網路診斷瑞士刀（nc）（圖 18）" loading="lazy" decoding="async"></p>
<ul>
<li><strong>在兩台 Server 間複製檔案</strong></li>
</ul>
<p>在接收檔案的 Server 上執行 <code>nc -l 5000 &gt; demo.js</code> ，在傳送檔案的 Server 上執行 <code>nc [host] 5000 &lt; demo.js</code></p>
<p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-19.webp" width="1400" height="190" alt="網路診斷瑞士刀（nc）（圖 19）" loading="lazy" decoding="async"></p>
<p>這個操作跟 <code>scp</code> 很類似，但特別的地方在於不需要登入的動作（不需要帳號密碼），假使遇到兩台 Server 無法互相登入時， 他就是一個解決方案。</p>
<blockquote>
<p>Netcat 還有非常多的功能，有興趣的可以再自行鑽研。</p>
</blockquote>
<h3 id="-設定好-dns-後確認回應是否正常nslookup">設定好 DNS 後，確認回應是否正常（nslookup）<a class="h-anchor" href="#-%e8%a8%ad%e5%ae%9a%e5%a5%bd-dns-%e5%be%8c%e7%a2%ba%e8%aa%8d%e5%9b%9e%e6%87%89%e6%98%af%e5%90%a6%e6%ad%a3%e5%b8%b8nslookup" aria-label="這個段落的連結"></a></h3>
<p>下面以查詢 google.com 的 ip 為例： <code>nslookup google.com</code></p>
<p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-20.webp" width="1156" height="324" alt="設定好 DNS 後，確認回應是否正常（nslookup）（圖 20）" loading="lazy" decoding="async"></p>
<p>在執行結果中「192.168.220.186」是查詢的 DNS Server，而「172.217.160.110」則是返回的 ip。</p>
<blockquote>
<p>在內網/外網執行時會有不同回應，可用來確認設定是否符合預期。</p>
</blockquote>
<h3 id="-查詢佔用的-portlsof">查詢佔用的 port（lsof）<a class="h-anchor" href="#-%e6%9f%a5%e8%a9%a2%e4%bd%94%e7%94%a8%e7%9a%84-portlsof" aria-label="這個段落的連結"></a></h3>
<p>lsof （List Open Files）可以列出所有被行程打開的檔案，筆者會透過這個指令來看 port 被哪個行程佔用了。</p>
<pre tabindex="0"><code>lsof -i -P | grep :443
</code></pre><p><code>-i</code> 是查找網路連線， <code>-P</code> 是列出實際的 port，最後透過 <code>grep</code> 將 port 為 443 的顯示出來。</p>
<p><img src="https://deanlin.net/blog/202208/useful-linux-commands/images/useful-linux-commands-21.webp" width="1400" height="127" alt="查詢佔用的 port（lsof）（圖 21）" loading="lazy" decoding="async"></p>
<blockquote class="pullquote"><p>以上是筆者常用的 Linux 指令，如果你平常有用到其他實用的指令，也歡迎留言分享喔！</p>
</blockquote>
]]></content:encoded>
    </item>
  </channel>
</rss>
